[haiku-commits] haiku: hrev44070 - in src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860: . src/add-ons/kernel/drivers/network/wlan/ralink2860

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 27 Apr 2012 06:07:21 +0200 (CEST)

hrev44070 adds 2 changesets to branch 'master'
old head: e5b4a1671d907d14bf0b61efc30a93de7c96709d
new head: 3245d56441da19afcf181faa05b9880e9839825b

----------------------------------------------------------------------------

e2b24ac: Update ralink2860 to Korli's version from ticket #8325.

3245d56: Cleanup POP3 connection code.
  * Use the ServerConnection class in POP3 too. This means no #ifdef USE_SSL 
for the connection anymore.
  * I remember from the mailing list that there were problems with to many open 
connection using POP3. Thus, if there is an error or nothing to retrieve close 
the connection.

                                     [ czeidler <haiku@xxxxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

28 files changed, 4330 insertions(+), 1403 deletions(-)
.../kernel/drivers/network/wlan/ralink2860/Jamfile |   10 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860.c      |  245 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_amrr.c |    2 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_amrr.h |    0
.../ralink2860/{ => dev/rt2860}/rt2860_debug.h     |    0
.../ralink2860/{ => dev/rt2860}/rt2860_eeprom.h    |   17 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_io.c   |  318 ++-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_io.h   |   24 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_led.c  |    8 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_led.h  |    4 +-
.../wlan/ralink2860/dev/rt2860/rt2860_nexus.c      |   93 +
.../wlan/ralink2860/dev/rt2860/rt2860_pci.c        |  164 ++
.../{ => dev/rt2860}/rt2860_read_eeprom.c          |   64 +-
.../{ => dev/rt2860}/rt2860_read_eeprom.h          |    2 +-
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_reg.h  |  178 +-
.../network/wlan/ralink2860/dev/rt2860/rt2860_rf.c | 1144 +++++++++
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_rf.h   |   19 +-
.../ralink2860/{ => dev/rt2860}/rt2860_rxdesc.h    |    0
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_rxwi.h |    0
.../ralink2860/{ => dev/rt2860}/rt2860_softc.h     |   85 +-
.../ralink2860/{ => dev/rt2860}/rt2860_txdesc.h    |    0
.../wlan/ralink2860/{ => dev/rt2860}/rt2860_txwi.h |    0
.../wlan/ralink2860/dev/rt2860/rt2860_ucode.h      | 2104 ++++++++++++++++
.../kernel/drivers/network/wlan/ralink2860/glue.c  |    6 +-
.../drivers/network/wlan/ralink2860/rt2860_rf.c    |  391 ---
.../drivers/network/wlan/ralink2860/rt2860_ucode.h |  566 -----
.../mail_daemon/inbound_protocols/pop3/pop3.cpp    |  268 +-
.../mail_daemon/inbound_protocols/pop3/pop3.h      |   21 +-

############################################################################

Commit:      e2b24ac4ba48347e355f1df86142f75641cba642
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e2b24ac
Author:      czeidler <haiku@xxxxxxxxxxxxxxxxxx>
Date:        Thu Apr 19 07:23:28 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/8325

Update ralink2860 to Korli's version from ticket #8325.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/Jamfile 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/Jamfile
index eabb42f..e624b43 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/Jamfile
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/Jamfile
@@ -13,14 +13,20 @@ SubDirCcFlags [ FDefines _KERNEL=1 FBSD_DRIVER=1 ]
 
 UseHeaders [ FDirName $(SUBDIR) ] : true ;
 
+SEARCH_SOURCE += [ FDirName $(SUBDIR) dev rt2860 ] ;
+UseHeaders [ FDirName $(SUBDIR) dev rt2860 ] : true ;
+
 KernelAddon ralink2860 :
        glue.c
        rt2860.c
+       rt2860_amrr.c
        rt2860_io.c
-       rt2860_read_eeprom.c
        rt2860_led.c
+       rt2860_nexus.c
+       rt2860_pci.c
+       rt2860_read_eeprom.c
        rt2860_rf.c
-       rt2860_amrr.c
+       
        :
        libfreebsd_wlan.a
        libfreebsd_network.a
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860.c
similarity index 98%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860.c
rename to src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860.c
index 934ca56..e920deb 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860.c
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860.c
@@ -16,28 +16,22 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "rt2860_softc.h"
-#include "rt2860_reg.h"
-#include "rt2860_eeprom.h"
-#include "rt2860_ucode.h"
-#include "rt2860_txwi.h"
-#include "rt2860_rxwi.h"
-#include "rt2860_io.h"
-#include "rt2860_read_eeprom.h"
-#include "rt2860_led.h"
-#include "rt2860_rf.h"
-#include "rt2860_debug.h"
+#include <dev/rt2860/rt2860_softc.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_ucode.h>
+#include <dev/rt2860/rt2860_txwi.h>
+#include <dev/rt2860/rt2860_rxwi.h>
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_read_eeprom.h>
+#include <dev/rt2860/rt2860_led.h>
+#include <dev/rt2860/rt2860_rf.h>
+#include <dev/rt2860/rt2860_debug.h>
 
 /*
  * Defines and macros
  */
 
-#define PCI_VENDOR_RALINK                                              0x1814
-#define PCI_PRODUCT_RALINK_RT2860_PCI                  0x0601
-#define PCI_PRODUCT_RALINK_RT2860_PCIe                 0x0681
-#define PCI_PRODUCT_RALINK_RT2760_PCI                  0x0701
-#define PCI_PRODUCT_RALINK_RT2790_PCIe                 0x0781
-
 #define RT2860_MAX_AGG_SIZE                                            3840
 
 #define RT2860_TX_DATA_SEG0_SIZE                               \
@@ -57,31 +51,22 @@
 #define RT2860_WCID_MCAST                                              0xf7
 
 /*
- * Data structures and types
+ * Global function prototypes, used in bus depended interfaces
  */
 
-struct rt2860_pci_ident
-{
-       uint16_t vendor;
-       uint16_t device;
-       const char *name;
-};
+int rt2860_attach(device_t dev);
 
-/*
- * Static function prototypes
- */
-
-static int rt2860_probe(device_t dev);
+int rt2860_detach(device_t dev);
 
-static int rt2860_attach(device_t dev);
+int rt2860_shutdown(device_t dev);
 
-static int rt2860_detach(device_t dev);
+int rt2860_suspend(device_t dev);
 
-static int rt2860_shutdown(device_t dev);
+int rt2860_resume(device_t dev);
 
-static int rt2860_suspend(device_t dev);
-
-static int rt2860_resume(device_t dev);
+/*
+ * Static function prototypes
+ */
 
 static void rt2860_init_channels(struct rt2860_softc *sc);
 
@@ -253,9 +238,11 @@ static int rt2860_tx_mgmt(struct rt2860_softc *sc,
 static int rt2860_tx_data(struct rt2860_softc *sc,
        struct mbuf *m, struct ieee80211_node *ni, int qid);
 
+/*
 static int rt2860_tx_raw(struct rt2860_softc *sc,
        struct mbuf *m, struct ieee80211_node *ni,
        const struct ieee80211_bpf_params *params);
+*/
 
 static void rt2860_intr(void *arg);
 
@@ -341,15 +328,6 @@ static void rt2860_sysctl_attach(struct rt2860_softc *sc);
  * Static variables
  */
 
-static const struct rt2860_pci_ident rt2860_pci_ids[] =
-{
-       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2860_PCI, "Ralink RT2860 PCI" 
},
-       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2860_PCIe, "Ralink RT2860 
PCIe" },
-       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2760_PCI, "Ralink RT2760 PCI" 
},
-       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2790_PCIe, "Ralink RT2790 
PCIe" },
-       { 0, 0, NULL }
-};
-
 static const struct
 {
        uint32_t reg;
@@ -423,35 +401,16 @@ SYSCTL_INT(_hw_rt2860, OID_AUTO, tx_stbc, CTLFLAG_RW, 
&rt2860_tx_stbc, 0, "RT286
 TUNABLE_INT("hw.rt2860.tx_stbc", &rt2860_tx_stbc);
 
 #ifdef RT2860_DEBUG
+//static int rt2860_debug = 0xffffffff;
 static int rt2860_debug = 0;
 SYSCTL_INT(_hw_rt2860, OID_AUTO, debug, CTLFLAG_RW, &rt2860_debug, 0, "RT2860 
debug level");
 TUNABLE_INT("hw.rt2860.debug", &rt2860_debug);
 #endif
 
 /*
- * rt2860_probe
- */
-static int rt2860_probe(device_t dev)
-{
-       const struct rt2860_pci_ident *ident;
-
-       for (ident = rt2860_pci_ids; ident->name != NULL; ident++)
-       {
-               if (pci_get_vendor(dev) == ident->vendor &&
-                       pci_get_device(dev) == ident->device)
-               {
-                       device_set_desc(dev, ident->name);
-                       return 0;
-               }
-       }
-
-       return ENXIO;
-}
-
-/*
  * rt2860_attach
  */
-static int rt2860_attach(device_t dev)
+int rt2860_attach(device_t dev)
 {
        struct rt2860_softc *sc;
        struct ifnet *ifp;
@@ -460,23 +419,11 @@ static int rt2860_attach(device_t dev)
 
        sc = device_get_softc(dev);
 
-       if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0)
-       {
-               printf("%s: chip is in D%d power mode, setting to D0\n",
-                       device_get_nameunit(dev), pci_get_powerstate(dev));
-               pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-       }
-
-       /* enable bus-mastering */
-
-       pci_enable_busmaster(dev);
-
        sc->dev = dev;
 
        mtx_init(&sc->lock, device_get_nameunit(dev),
                MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE);
 
-       sc->mem_rid = PCIR_BAR(0);
        sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
                &sc->mem_rid, RF_ACTIVE);
        if (sc->mem == NULL)
@@ -487,9 +434,10 @@ static int rt2860_attach(device_t dev)
                goto fail;
        }
 
+
        sc->bst = rman_get_bustag(sc->mem);
        sc->bsh = rman_get_bushandle(sc->mem);
-       
+
        sc->irq_rid = 0;
        sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
                &sc->irq_rid, RF_ACTIVE | RF_SHAREABLE);
@@ -766,7 +714,7 @@ fail:
 /*
  * rt2860_detach
  */
-static int rt2860_detach(device_t dev)
+int rt2860_detach(device_t dev)
 {
        struct rt2860_softc *sc;
        struct ifnet *ifp;
@@ -824,7 +772,7 @@ static int rt2860_detach(device_t dev)
 /*
  * rt2860_shutdown
  */
-static int rt2860_shutdown(device_t dev)
+int rt2860_shutdown(device_t dev)
 {
        struct rt2860_softc *sc;
 
@@ -844,7 +792,7 @@ static int rt2860_shutdown(device_t dev)
 /*
  * rt2860_suspend
  */
-static int rt2860_suspend(device_t dev)
+int rt2860_suspend(device_t dev)
 {
        struct rt2860_softc *sc;
 
@@ -864,7 +812,7 @@ static int rt2860_suspend(device_t dev)
 /*
  * rt2860_resume
  */
-static int rt2860_resume(device_t dev)
+int rt2860_resume(device_t dev)
 {
        struct rt2860_softc *sc;
        struct ifnet *ifp;
@@ -931,7 +879,8 @@ static void rt2860_init_channels(struct rt2860_softc *sc)
        /* set supported channels for 5GHz band */
 
        if (sc->rf_rev == RT2860_EEPROM_RF_2850 ||
-               sc->rf_rev == RT2860_EEPROM_RF_2750)
+               sc->rf_rev == RT2860_EEPROM_RF_2750 ||
+               sc->rf_rev == RT2860_EEPROM_RF_3052)
        {
                for (i = 36; i <= 64; i += 4)
                {
@@ -1045,7 +994,8 @@ static void rt2860_init_channels_ht40(struct rt2860_softc 
*sc)
        /* set supported channels for 5GHz band */
 
        if (sc->rf_rev == RT2860_EEPROM_RF_2850 ||
-               sc->rf_rev == RT2860_EEPROM_RF_2750)
+               sc->rf_rev == RT2860_EEPROM_RF_2750 ||
+               sc->rf_rev == RT2860_EEPROM_RF_3052)
        {
                for (i = 36; i <= 64; i += 4)
                {
@@ -1193,8 +1143,10 @@ static void rt2860_init_locked(void *priv)
 
        RT2860_SOFTC_ASSERT_LOCKED(sc);
 
-       if (!(sc->flags & RT2860_SOFTC_FLAGS_UCODE_LOADED))
+       if (sc->mac_rev != 0x28720200)
        {
+           if (!(sc->flags & RT2860_SOFTC_FLAGS_UCODE_LOADED))
+           {
                RT2860_DPRINTF(sc, RT2860_DEBUG_ANY,
                        "%s: loading 8051 microcode\n",
                        device_get_nameunit(sc->dev));
@@ -1212,6 +1164,28 @@ static void rt2860_init_locked(void *priv)
                        device_get_nameunit(sc->dev));
 
                sc->flags |= RT2860_SOFTC_FLAGS_UCODE_LOADED;
+           }
+       }
+       else
+       {
+               sc->flags |= RT2860_SOFTC_FLAGS_UCODE_LOADED;
+
+               /* Blink every TX */
+#define LED_CFG_LED_POLARITY   (1<<30)
+#define LED_CFG_Y_LED_MODE_ONTX        (1<<28)
+#define LED_CFG_G_LED_MODE_ONTX        (1<<26)
+#define LED_CFG_R_LED_MODE_ONTX        (1<<24)
+#define LED_CFG_SLOW_BLK_TIME  (0x03<<16) /* sec */
+#define LED_CFG_LED_OFF_TIME   (0x1e<<8) /* msec */
+#define LED_CFG_LED_ON_TIME    (0x46) /* msec */
+               rt2860_io_mac_write(sc, RT2860_REG_LED_CFG, 
+                   LED_CFG_LED_POLARITY |
+                   LED_CFG_Y_LED_MODE_ONTX |
+                   LED_CFG_G_LED_MODE_ONTX |
+                   LED_CFG_R_LED_MODE_ONTX |
+                   LED_CFG_SLOW_BLK_TIME |
+                   LED_CFG_LED_OFF_TIME |
+                   LED_CFG_LED_ON_TIME);
        }
 
        rt2860_io_mac_write(sc, RT2860_REG_PWR_PIN_CFG, 0x2);
@@ -1434,8 +1408,13 @@ static void rt2860_init_locked(void *priv)
 
        rt2860_io_mac_write(sc, RT2860_REG_SCHDMA_DELAY_INT_CFG, 0);
 
-       /* send LEDs operating mode to microcontroller */
+       /* select Main antenna for 1T1R devices */
+       if (sc->rf_rev == RT2860_EEPROM_RF_2020 ||
+           sc->rf_rev == RT2860_EEPROM_RF_3020 ||
+           sc->rf_rev == RT2860_EEPROM_RF_3320)
+               rt3090_set_rx_antenna(sc, 0);
 
+       /* send LEDs operating mode to microcontroller */
        rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_LED1,
                RT2860_REG_H2M_TOKEN_NO_INTR, sc->led_off[0]);
        rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_LED2,
@@ -1459,18 +1438,26 @@ static void rt2860_init_locked(void *priv)
                        sc->bbp_eeprom[i].val);
        }
 
-       tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
-       if (tmp & (1 << 2))
-       {
-               rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
-                       RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
-               rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_RADIOOFF);
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000)
+               rt3090_rf_init(sc);
 
-               rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
-                       RT2860_REG_H2M_TOKEN_WAKEUP, 0);
-               rt2860_io_mcu_cmd_check(sc, RT2860_REG_H2M_TOKEN_WAKEUP);
+       if (sc->mac_rev != 0x28720200) {
+               /* 0x28720200 don`t have RT2860_REG_SCHDMA_GPIO_CTRL_CFG */
+               tmp = rt2860_io_mac_read(sc, RT2860_REG_SCHDMA_GPIO_CTRL_CFG);
+               if (tmp & (1 << 2)) {
+                       rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_SLEEP,
+                               RT2860_REG_H2M_TOKEN_RADIOOFF, 0x02ff);
+                       rt2860_io_mcu_cmd_check(sc, 
RT2860_REG_H2M_TOKEN_RADIOOFF);
+
+                       rt2860_io_mcu_cmd(sc, RT2860_IO_MCU_CMD_WAKEUP,
+                               RT2860_REG_H2M_TOKEN_WAKEUP, 0);
+                       rt2860_io_mcu_cmd_check(sc, 
RT2860_REG_H2M_TOKEN_WAKEUP);
+               }
        }
 
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000)
+               rt3090_rf_wakeup(sc);
+
        /* disable non-existing Rx chains */
 
        tmp = rt2860_io_bbp_read(sc, 3);
@@ -1495,10 +1482,26 @@ static void rt2860_init_locked(void *priv)
 
        rt2860_io_bbp_write(sc, 1, tmp);
 
-       /* set current channel */
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000)
+               rt3090_rf_setup(sc);
 
+       if (sc->rf_rev == RT2860_EEPROM_RF_3022)
+       {
+               /* calibrate RF */
+                tmp = rt2860_io_rf_read(sc, 30);
+                tmp |= 0x80;
+                rt2860_io_rf_write(sc, 30, tmp);
+                DELAY(1000);
+                tmp &= 0x7F;
+                rt2860_io_rf_write(sc, 30, tmp);
+
+                /* Initialize RF register to default value */
+               rt2860_io_rf_load_defaults(sc);
+       }
+
+       /* set current channel */
        rt2860_rf_set_chan(sc, ic->ic_curchan);
-       
+
        rt2860_io_mac_write(sc, RT2860_REG_SCHDMA_WMM_TXOP0_CFG, 0);
        rt2860_io_mac_write(sc, RT2860_REG_SCHDMA_WMM_TXOP1_CFG,
                (48 << 16) | 96);
@@ -2269,6 +2272,10 @@ static int rt2860_vap_key_set(struct ieee80211vap *vap,
                /* install pairwise key */
 
                ni = ieee80211_find_vap_node(&ic->ic_sta, vap, mac);
+               if (!ni) {
+                       printf("ieee80211_find_vap_node return 0\n");
+                       return 0;
+               }
                rni = (struct rt2860_softc_node *) ni;
 
                vapid = 0;
@@ -4307,6 +4314,9 @@ static int rt2860_tx_mgmt(struct rt2860_softc *sc,
        wh = mtod(m, struct ieee80211_frame *);
 
        rate = tp->mgmtrate & IEEE80211_RATE_VAL;
+/* XXX */
+       if (!rate)
+               return EFBIG;
 
        /* fill Tx wireless info */
 
@@ -4458,7 +4468,7 @@ static int rt2860_tx_mgmt(struct rt2860_softc *sc,
        m_adj(m, hdrspace);
 
        error = bus_dmamap_load_mbuf_sg(ring->data_dma_tag, data->dma_map, m,
-           dma_seg, &ndmasegs, 0);
+           dma_seg, &ndmasegs, BUS_DMA_NOWAIT);
        if (error != 0)
        {
                /* too many fragments, linearize */
@@ -4474,7 +4484,7 @@ static int rt2860_tx_mgmt(struct rt2860_softc *sc,
                sc->tx_defrag_packets++;
 
                error = bus_dmamap_load_mbuf_sg(ring->data_dma_tag, 
data->dma_map, m,
-               dma_seg, &ndmasegs, 0);
+               dma_seg, &ndmasegs, BUS_DMA_NOWAIT);
                if (error != 0)
                {
                        printf("%s: could not load mbuf DMA map: ndmasegs=%d, 
len=%d, error=%d\n",
@@ -4657,6 +4667,9 @@ static int rt2860_tx_data(struct rt2860_softc *sc,
                rate = ni->ni_txrate;
 
        rate &= IEEE80211_RATE_VAL;
+/* XXX */
+       if (!rate)
+               return EFBIG;
 
        /* fill Tx wireless info */
 
@@ -4864,7 +4877,7 @@ static int rt2860_tx_data(struct rt2860_softc *sc,
        m_adj(m, hdrspace);
 
        error = bus_dmamap_load_mbuf_sg(ring->data_dma_tag, data->dma_map, m,
-           dma_seg, &ndmasegs, 0);
+           dma_seg, &ndmasegs, BUS_DMA_NOWAIT);
        if (error != 0)
        {
                /* too many fragments, linearize */
@@ -4880,7 +4893,7 @@ static int rt2860_tx_data(struct rt2860_softc *sc,
                sc->tx_defrag_packets++;
 
                error = bus_dmamap_load_mbuf_sg(ring->data_dma_tag, 
data->dma_map, m,
-               dma_seg, &ndmasegs, 0);
+               dma_seg, &ndmasegs, BUS_DMA_NOWAIT);
                if (error != 0)
                {
                        printf("%s: could not load mbuf DMA map: ndmasegs=%d, 
len=%d, error=%d\n",
@@ -4995,7 +5008,6 @@ static int rt2860_tx_data(struct rt2860_softc *sc,
 
 /*
  * rt2860_tx_raw
- */
 static int rt2860_tx_raw(struct rt2860_softc *sc,
        struct mbuf *m, struct ieee80211_node *ni,
        const struct ieee80211_bpf_params *params)
@@ -5006,6 +5018,7 @@ static int rt2860_tx_raw(struct rt2860_softc *sc,
 
        return 0;
 }
+ */
 
 /*
  * rt2860_intr
@@ -5017,7 +5030,6 @@ static void rt2860_intr(void *arg)
        uint32_t status;
 
        sc = arg;
-
 #if !defined(__HAIKU__)
        ifp = sc->ifp;
 
@@ -5038,6 +5050,7 @@ static void rt2860_intr(void *arg)
 
        if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
                return;
+
 #else
        status = sc->interrupt_status;
 #endif
@@ -5652,9 +5665,10 @@ static int rt2860_rx_eof(struct rt2860_softc *sc, int 
limit)
 
                bus_dmamap_sync(ring->desc_dma_tag, ring->desc_dma_map,
                        BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
-
+#ifdef XXX_TESTED_AND_WORKED
                if (!(desc->sdl0 & htole16(RT2860_RXDESC_SDL0_DDONE)))
                        break;
+#endif
 
                nframes++;
 
@@ -7161,27 +7175,4 @@ static void rt2860_sysctl_attach(struct rt2860_softc *sc)
                "Rx cipher invalid key errors");
 }
 
-static device_method_t rt2860_dev_methods[] =
-{
-       DEVMETHOD(device_probe, rt2860_probe),
-       DEVMETHOD(device_attach, rt2860_attach),
-       DEVMETHOD(device_detach, rt2860_detach),
-       DEVMETHOD(device_shutdown, rt2860_shutdown),
-       DEVMETHOD(device_suspend, rt2860_suspend),
-       DEVMETHOD(device_resume, rt2860_resume),
-       { 0, 0 }
-};
-
-static driver_t rt2860_driver =
-{
-       "rt2860",
-       rt2860_dev_methods,
-       sizeof(struct rt2860_softc)
-};
-
-static devclass_t rt2860_dev_class;
-
-DRIVER_MODULE(rt2860, pci, rt2860_driver, rt2860_dev_class, 0, 0);
 
-MODULE_DEPEND(rt2860, pci, 1, 1, 1);
-MODULE_DEPEND(rt2860, wlan, 1, 1, 1);
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_amrr.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_amrr.c
similarity index 99%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_amrr.c
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_amrr.c
index d60e871..224c4d4 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_amrr.c
+++ 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_amrr.c
@@ -27,7 +27,7 @@
 
 #include <net80211/ieee80211_var.h>
 
-#include "rt2860_amrr.h"
+#include <dev/rt2860/rt2860_amrr.h>
 
 /*
  * Defines and macros
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_amrr.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_amrr.h
similarity index 100%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_amrr.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_amrr.h
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_debug.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_debug.h
similarity index 100%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_debug.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_debug.h
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_eeprom.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_eeprom.h
similarity index 76%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_eeprom.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_eeprom.h
index a8b94e2..52ed41b 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_eeprom.h
+++ 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_eeprom.h
@@ -33,7 +33,9 @@
 #define RT2860_EEPROM_LED3_OFF                                 0x0040
 #define RT2860_EEPROM_LNA_GAIN                                 0x0044
 #define RT2860_EEPROM_RSSI_OFF_2GHZ_BASE               0x0046
-#define RT2860_EEPROM_RSSI_OFF_5GHZ_BASE               0x0046
+#define RT2860_EEPROM_RSSI2_OFF_2GHZ_BASE              0x0048
+#define RT2860_EEPROM_RSSI_OFF_5GHZ_BASE               0x004a
+#define RT2860_EEPROM_RSSI2_OFF_5GHZ_BASE              0x004c
 #define RT2860_EEPROM_TXPOW_RATE_DELTA                 0x0050
 #define RT2860_EEPROM_TXPOW1_2GHZ_BASE                 0x0052
 #define RT2860_EEPROM_TXPOW2_2GHZ_BASE                 0x0060
@@ -42,12 +44,23 @@
 #define RT2860_EEPROM_TXPOW2_5GHZ_BASE                 0x00a6
 #define RT2860_EEPROM_TSSI_5GHZ_BASE                   0x00d4
 #define RT2860_EEPROM_TXPOW_RATE_BASE                  0x00de
-#define RT2860_EEPROM_BBP_BASE                                 0x00f0
+#define RT2860_EEPROM_BBP_BASE                         0x00f0
+#define RT3071_EEPROM_RF_BASE                          0x0082
 
 #define RT2860_EEPROM_RF_2820                                  1 /* 2.4GHz 
2T3R */
 #define RT2860_EEPROM_RF_2850                                  2 /* 2.4/5GHz 
2T3R */
 #define RT2860_EEPROM_RF_2720                                  3 /* 2.4GHz 
1T2R */
 #define RT2860_EEPROM_RF_2750                                  4 /* 2.4G/5GHz 
1T2R */
+#define RT2860_EEPROM_RF_3020                                  5 /* 2.4G 1T1R 
*/
+#define RT2860_EEPROM_RF_2020                                  6 /* 2.4G B/G */
+#define RT2860_EEPROM_RF_3021                                  7 /* 2.4G 1T2R 
*/
+#define RT2860_EEPROM_RF_3022                                  8 /* 2.4G 2T2R 
*/
+#define RT2860_EEPROM_RF_3052                                  9 /* 2.4G/5G 
2T2R */
+#define RT2860_EEPROM_RF_2853                                  10 /* 2.4G.5G 
3T3R */
+#define RT2860_EEPROM_RF_3320                                  11 /* 2.4G 1T1R 
with PA (RT3350/RT3370/RT3390) */
+#define RT2860_EEPROM_RF_3322                                  12 /* 2.4G 2T2R 
with PA (RT3352/RT3371/RT3372/RT3391/RT3392) */
+#define RT2860_EEPROM_RF_3053                                  13 /* 2.4G/5G 
3T3R (RT3883/RT3563/RT3573/RT3593/RT3662) */
+#define RT2860_EEPROM_RF_3853                                  13 /* 2.4G/5G 
3T3R (RT3883/RT3563/RT3573/RT3593/RT3662) */
 
 /*
  * RT2860_EEPROM_NIC_CONFIG flags
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.c
similarity index 60%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.c
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.c
index e8eecb8..e7f1395 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.c
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.c
@@ -16,8 +16,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "rt2860_io.h"
-#include "rt2860_reg.h"
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_reg.h>
 
 /*
  * Defines and macros
@@ -63,6 +63,80 @@ static uint16_t rt2860_io_eeprom_shiftin_bits(struct 
rt2860_softc *sc);
 
 static uint8_t rt2860_io_byte_rev(uint8_t byte);
 
+/* #ifdef RT305X_SOC */
+static const uint16_t rt3052_eeprom[] = 
+{
+       0x3052, 0x0101, 0x0c00, 0x3043, 0x8852, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0x0c00, 0x3043, 0x7752, 0x0c00,
+       0x3043, 0x6652, 0x0822, 0x0024, 0xffff, 0x012f, 0x7755, 0xaaa8,
+       0x888c, 0xffff, 0x000c, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff,
+       0xffff, 0x0d0d, 0x0d0d, 0x0c0c, 0x0c0c, 0x0c0c, 0x0c0c, 0x0c0c,
+       0x1010, 0x1111, 0x1211, 0x1212, 0x1313, 0x1413, 0x1414, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6666,
+       0xaacc, 0x6688, 0xaacc, 0x6688, 0xaacc, 0x6688, 0xaacc, 0x6688,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+       0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+};
+
+uint8_t rt3052_rf_default[] = {
+       0x50,
+       0x01,
+       0xF7,
+       0x75,
+       0x40,
+       0x03,
+       0x42,
+       0x50,
+       0x39,
+       0x0F,
+       0x60,
+       0x21,
+       0x75,
+       0x75,
+       0x90,
+       0x58,
+       0xB3,
+       0x92,
+       0x2C,
+       0x02,
+       0xBA,
+       0xDB,
+       0x00,
+       0x31,
+       0x08,
+       0x01,
+       0x25, /* Core Power: 0x25=1.25V */
+       0x23, /* RF: 1.35V */
+       0x13, /* ADC: must consist with R27 */
+       0x83,
+       0x00,
+       0x00,
+};
+/* #endif */
+
+
 /*
  * Static variables
  */
@@ -108,6 +182,7 @@ static const uint16_t rt2860_io_ccitt16[] =
  */
 uint32_t rt2860_io_mac_read(struct rt2860_softc *sc, uint16_t reg)
 {
+       bus_space_read_4(sc->bst, sc->bsh, RT2860_REG_MAC_CSR0);
        return bus_space_read_4(sc->bst, sc->bsh, reg);
 }
 
@@ -117,6 +192,7 @@ uint32_t rt2860_io_mac_read(struct rt2860_softc *sc, 
uint16_t reg)
 void rt2860_io_mac_read_multi(struct rt2860_softc *sc,
        uint16_t reg, void *buf, size_t len)
 {
+       bus_space_read_4(sc->bst, sc->bsh, RT2860_REG_MAC_CSR0);
        bus_space_read_region_1(sc->bst, sc->bsh, reg, buf, len);
 }
 
@@ -126,6 +202,7 @@ void rt2860_io_mac_read_multi(struct rt2860_softc *sc,
 void rt2860_io_mac_write(struct rt2860_softc *sc,
        uint16_t reg, uint32_t val)
 {
+       bus_space_read_4(sc->bst, sc->bsh, RT2860_REG_MAC_CSR0);
        bus_space_write_4(sc->bst, sc->bsh, reg, val);
 }
 
@@ -135,7 +212,15 @@ void rt2860_io_mac_write(struct rt2860_softc *sc,
 void rt2860_io_mac_write_multi(struct rt2860_softc *sc,
        uint16_t reg, const void *buf, size_t len)
 {
-       bus_space_write_region_1(sc->bst, sc->bsh, reg, buf, len);
+       int i;
+       const uint8_t *p;
+
+       bus_space_read_4(sc->bst, sc->bsh, RT2860_REG_MAC_CSR0);
+
+       p = buf;
+       for (i = 0; i < len; i ++)
+               bus_space_write_1(sc->bst, sc->bsh, reg + i, *(p+i));
+//     bus_space_write_region_1(sc->bst, sc->bsh, reg, buf, len);
 }
 
 /*
@@ -150,6 +235,46 @@ void rt2860_io_mac_set_region_4(struct rt2860_softc *sc,
                rt2860_io_mac_write(sc, reg + i, val);
 }
 
+/* Read 16-bit from eFUSE ROM (>=RT3071 only.) */
+static uint16_t
+rt3090_efuse_read_2(struct rt2860_softc *sc, uint16_t addr)
+{
+       uint32_t tmp;
+       uint16_t reg;
+       int ntries;
+
+       addr *= 2;
+       /*-
+        * Read one 16-byte block into registers EFUSE_DATA[0-3]:
+        * DATA0: F E D C
+        * DATA1: B A 9 8
+        * DATA2: 7 6 5 4
+        * DATA3: 3 2 1 0
+        */
+       tmp = rt2860_io_mac_read(sc, RT3070_EFUSE_CTRL);
+       tmp &= ~(RT3070_EFSROM_MODE_MASK | RT3070_EFSROM_AIN_MASK);
+       tmp |= (addr & ~0xf) << RT3070_EFSROM_AIN_SHIFT | RT3070_EFSROM_KICK;
+       rt2860_io_mac_write(sc, RT3070_EFUSE_CTRL, tmp);
+       for (ntries = 0; ntries < 500; ntries++) {
+               tmp = rt2860_io_mac_read(sc, RT3070_EFUSE_CTRL);
+               if (!(tmp & RT3070_EFSROM_KICK))
+                       break;
+               DELAY(2);
+       }
+       if (ntries == 500)
+               return 0xffff;
+
+       if ((tmp & RT3070_EFUSE_AOUT_MASK) == RT3070_EFUSE_AOUT_MASK)
+               return 0xffff;  /* address not found */
+
+       /* determine to which 32-bit register our 16-bit word belongs */
+       reg = RT3070_EFUSE_DATA3 - (addr & 0xc);
+       tmp = rt2860_io_mac_read(sc, reg);
+
+       return (addr & 2) ? tmp >> 16 : tmp & 0xffff;
+}
+
+
 /*
  * rt2860_io_eeprom_read
  */
@@ -160,6 +285,14 @@ uint16_t rt2860_io_eeprom_read(struct rt2860_softc *sc, 
uint16_t addr)
 
        addr = (addr >> 1);
 
+       if (sc->mac_rev == 0x28720200) {
+               return (rt3052_eeprom[addr]);
+       } else if ((sc->mac_rev & 0xffff0000) >= 0x30710000) {
+               tmp = rt2860_io_mac_read(sc, RT3070_EFUSE_CTRL);
+               if (tmp & RT3070_SEL_EFUSE)
+                       return (rt3090_efuse_read_2(sc, addr));
+       }
+
        tmp = rt2860_io_mac_read(sc, RT2860_REG_EEPROM_CSR);
 
        tmp &= ~(RT2860_REG_EEDI | RT2860_REG_EEDO | RT2860_REG_EESK);
@@ -224,6 +357,43 @@ uint8_t rt2860_io_bbp_read(struct rt2860_softc *sc, 
uint8_t reg)
        int ntries;
        uint32_t tmp;
 
+       if (sc->mac_rev == 0x28720200)
+       {
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2860_REG_BBP_CSR_CFG) & 
+                           RT2860_REG_BBP_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: BBP busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+                       return (0);
+               }
+               rt2860_io_mac_write(sc, RT2860_REG_BBP_CSR_CFG, 
+                   RT2860_REG_BBP_CSR_READ |
+                   RT2860_REG_BBP_CSR_KICK | RT2860_REG_BBP_RW_MODE_PARALLEL |
+                   (reg & RT2860_REG_BBP_REG_MASK) << 
RT2860_REG_BBP_REG_SHIFT);
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2860_REG_BBP_CSR_CFG) & 
+                           RT2860_REG_BBP_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: BBP busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+                       return (0);
+               }
+               else {
+                       return 
+                           ((rt2860_io_mac_read(sc, RT2860_REG_BBP_CSR_CFG) >>
+                           RT2860_REG_BBP_VAL_SHIFT) & 
+                           RT2860_REG_BBP_VAL_MASK);
+               }
+               return (0);
+       }
+
        for (ntries = 0; ntries < 100; ntries++)
        {
                if (!(rt2860_io_mac_read(sc, RT2860_REG_H2M_MAILBOX_BBP_AGENT) &
@@ -276,6 +446,27 @@ void rt2860_io_bbp_write(struct rt2860_softc *sc, uint8_t 
reg, uint8_t val)
        int ntries;
        uint32_t tmp;
 
+       if (sc->mac_rev == 0x28720200)
+       {
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2860_REG_BBP_CSR_CFG) & 
+                           RT2860_REG_BBP_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: BBP busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+                       return;
+               }
+               rt2860_io_mac_write(sc, RT2860_REG_BBP_CSR_CFG, 
+                   RT2860_REG_BBP_CSR_KICK | RT2860_REG_BBP_RW_MODE_PARALLEL |
+                   (reg & RT2860_REG_BBP_REG_MASK) << RT2860_REG_BBP_REG_SHIFT 
| 
+                   (val & RT2860_REG_BBP_VAL_MASK) << RT2860_REG_BBP_VAL_SHIFT 
);
+               rt2860_io_bbp_read(sc, reg);
+               return;
+       }
+
        for (ntries = 0; ntries < 100; ntries++)
        {
                if (!(rt2860_io_mac_read(sc, RT2860_REG_H2M_MAILBOX_BBP_AGENT) &
@@ -311,6 +502,27 @@ void rt2860_io_bbp_write(struct rt2860_softc *sc, uint8_t 
reg, uint8_t val)
 void rt2860_io_rf_write(struct rt2860_softc *sc, uint8_t reg, uint32_t val)
 {
        int ntries;
+       if (sc->mac_rev == 0x28720200)
+       {
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2872_REG_RF_CSR_CFG) & 
+                           RT2872_REG_RF_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: RF busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+                       return;
+               }
+               rt2860_io_mac_write(sc, RT2872_REG_RF_CSR_CFG, 
+                   RT2872_REG_RF_CSR_KICK | RT2872_REG_RF_CSR_WRITE |
+                   (reg & RT2872_REG_RF_ID_MASK) << RT2872_REG_RF_ID_SHIFT | 
+                   (val & RT2872_REG_RF_VAL_MASK) << RT2872_REG_RF_VAL_SHIFT );
+               rt2860_io_rf_read(sc, reg);
+               return;
+       }
+
 
        for (ntries = 0; ntries < 100; ntries++)
                if (!(rt2860_io_mac_read(sc, RT2860_REG_RF_CSR_CFG0) &
@@ -328,6 +540,58 @@ void rt2860_io_rf_write(struct rt2860_softc *sc, uint8_t 
reg, uint32_t val)
 }
 
 /*
+ * rt2860_io_rf_read
+ */
+int32_t rt2860_io_rf_read(struct rt2860_softc *sc, uint8_t reg)
+{
+       int ntries;
+       if (sc->mac_rev == 0x28720200)
+       {
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2872_REG_RF_CSR_CFG) & 
+                           RT2872_REG_RF_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: RF busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+                       return (-1);
+               }
+               rt2860_io_mac_write(sc, RT2872_REG_RF_CSR_CFG, 
+                   RT2872_REG_RF_CSR_KICK |
+                   (reg & RT2872_REG_RF_ID_MASK) << RT2872_REG_RF_ID_SHIFT );
+
+               for (ntries = 0; ntries < 100; ntries ++) {
+                       if ( !(rt2860_io_mac_read(sc, RT2872_REG_RF_CSR_CFG) & 
+                           RT2872_REG_RF_CSR_BUSY) )
+                               break;
+                       DELAY(1);
+               }
+               if (ntries == 100) {
+                       printf("%s:%s: RF busy after 100 probes\n",
+                               device_get_nameunit(sc->dev), __func__);
+               }
+
+               return (rt2860_io_mac_read(sc, RT2872_REG_RF_CSR_CFG) & 
RT2872_REG_RF_VAL_MASK);
+       }
+       return (-1);
+}
+
+/*
+ * rt2860_io_rf_load_defaults
+ */
+void rt2860_io_rf_load_defaults(struct rt2860_softc *sc)
+{
+       int i;
+
+       if (sc->mac_rev == 0x28720200) {
+               for (i = 0; i < 32; i ++)
+                       rt2860_io_rf_write(sc, i, rt3052_rf_default[i]);
+       }
+}
+
+/*
  * rt2860_io_mcu_cmd
  */
 void rt2860_io_mcu_cmd(struct rt2860_softc *sc, uint8_t cmd,
@@ -336,6 +600,9 @@ void rt2860_io_mcu_cmd(struct rt2860_softc *sc, uint8_t cmd,
        uint32_t tmp;
        int ntries;
 
+       if (sc->mac_rev == 0x28720200)
+               return;
+
        for (ntries = 0; ntries < 100; ntries++)
        {
                if (!(rt2860_io_mac_read(sc, RT2860_REG_H2M_MAILBOX) &
@@ -437,30 +704,47 @@ int rt2860_io_mcu_load_ucode(struct rt2860_softc *sc,
 
        rt2860_io_mac_write(sc, RT2860_REG_PBF_SYS_CTRL, RT2860_REG_HST_PM_SEL);
 
-       rt2860_io_mac_write_multi(sc, RT2860_REG_MCU_UCODE_BASE, ucode, len);
+       for(i = 0; i < len; i += 4)
+       {
+               rt2860_io_mac_write(sc, RT2860_REG_MCU_UCODE_BASE + i, 
+                   (ucode[i+3] << 24) | (ucode[i+2] << 16) | 
+                   (ucode[i+1] << 8) | ucode[i]);
+       }
+
+       if (sc->mac_rev != 0x28720200)
+               rt2860_io_mac_write_multi(sc, RT2860_REG_MCU_UCODE_BASE,
+                   ucode, len);
 
        rt2860_io_mac_write(sc, RT2860_REG_PBF_SYS_CTRL, 0);
-       rt2860_io_mac_write(sc, RT2860_REG_PBF_SYS_CTRL, RT2860_REG_MCU_RESET);
+
+       if (sc->mac_rev != 0x28720200)
+               rt2860_io_mac_write(sc, RT2860_REG_PBF_SYS_CTRL,
+                   RT2860_REG_MCU_RESET);
+
+       DELAY(10000);
 
        /* initialize BBP R/W access agent */
 
        rt2860_io_mac_write(sc, RT2860_REG_H2M_MAILBOX_BBP_AGENT, 0);
        rt2860_io_mac_write(sc, RT2860_REG_H2M_MAILBOX, 0);
 
-       for (ntries = 0; ntries < 1000; ntries++)
-       {
-               if (rt2860_io_mac_read(sc, RT2860_REG_PBF_SYS_CTRL) &
-                       RT2860_REG_MCU_READY)
-                       break;
+       if (sc->mac_rev != 0x28720200) {
 
-               DELAY(1000);
-       }
+               for (ntries = 0; ntries < 1000; ntries++)
+               {
+                       if (rt2860_io_mac_read(sc, RT2860_REG_PBF_SYS_CTRL) &
+                               RT2860_REG_MCU_READY)
+                               break;
 
-       if (ntries == 1000)
-       {
-               printf("%s: timeout waiting for MCU to initialize\n",
-                       device_get_nameunit(sc->dev));
-               return ETIMEDOUT;
+                       DELAY(1000);
+               }
+
+               if (ntries == 1000)
+               {
+                       printf("%s: timeout waiting for MCU to initialize\n",
+                               device_get_nameunit(sc->dev));
+                       return ETIMEDOUT;
+               }
        }
 
        return 0;
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.h
similarity index 80%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.h
index 0d8b62b..818c3d2 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_io.h
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_io.h
@@ -19,20 +19,21 @@
 #ifndef _RT2860_IO_H_
 #define _RT2860_IO_H_
 
-#include "rt2860_softc.h"
+#include <dev/rt2860/rt2860_softc.h>
 
-#define RT2860_IO_MCU_CMD_SLEEP                                        0x30
-#define RT2860_IO_MCU_CMD_WAKEUP                               0x31
-#define RT2860_IO_MCU_CMD_RADIOOFF                             0x35
-#define RT2860_IO_MCU_CMD_LEDS                                 0x50
+#define RT2860_IO_MCU_CMD_SLEEP                                0x30
+#define RT2860_IO_MCU_CMD_WAKEUP                       0x31
+#define RT2860_IO_MCU_CMD_RADIOOFF                     0x35
+#define RT2860_IO_MCU_CMD_LEDS                         0x50
 #define RT2860_IO_MCU_CMD_LED_BRIGHTNESS               0x51
-#define RT2860_IO_MCU_CMD_LED1                                 0x52
-#define RT2860_IO_MCU_CMD_LED2                                 0x53
-#define RT2860_IO_MCU_CMD_LED3                                 0x54
-#define RT2860_IO_MCU_CMD_BOOT                                 0x72
-#define RT2860_IO_MCU_CMD_BBP                                  0x80
+#define RT2860_IO_MCU_CMD_LED1                         0x52
+#define RT2860_IO_MCU_CMD_LED2                         0x53
+#define RT2860_IO_MCU_CMD_LED3                         0x54
+#define RT2860_IO_MCU_CMD_BOOT                         0x72
+#define RT2860_IO_MCU_CMD_BBP                          0x80
 #define RT2860_IO_MCU_CMD_POWERSAVE_LEVEL              0x83
 
+void rt2860_io_rf_load_defaults(struct rt2860_softc *sc);
 uint32_t rt2860_io_mac_read(struct rt2860_softc *sc, uint16_t reg);
 
 void rt2860_io_mac_read_multi(struct rt2860_softc *sc,
@@ -58,6 +59,8 @@ void rt2860_io_bbp_write(struct rt2860_softc *sc, uint8_t 
reg, uint8_t val);
 
 void rt2860_io_rf_write(struct rt2860_softc *sc, uint8_t reg, uint32_t val);
 
+int32_t rt2860_io_rf_read(struct rt2860_softc *sc, uint8_t reg);
+
 void rt2860_io_mcu_cmd(struct rt2860_softc *sc, uint8_t cmd,
        uint8_t token, uint16_t arg);
 
@@ -66,4 +69,5 @@ int rt2860_io_mcu_cmd_check(struct rt2860_softc *sc, uint8_t 
cid);
 int rt2860_io_mcu_load_ucode(struct rt2860_softc *sc,
        const uint8_t *ucode, size_t len);
 
+
 #endif /* #ifndef _RT2860_IO_H_ */
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.c
similarity index 91%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.c
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.c
index a27dff4..98387de 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.c
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.c
@@ -16,10 +16,10 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "rt2860_led.h"
-#include "rt2860_reg.h"
-#include "rt2860_eeprom.h"
-#include "rt2860_io.h"
+#include <dev/rt2860/rt2860_led.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_io.h>
 
 /*
  * rt2860_led_brightness
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.h
similarity index 94%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.h
index 74f4791..e0fbf79 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_led.h
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_led.h
@@ -19,7 +19,7 @@
 #ifndef _RT2860_LED_H_
 #define _RT2860_LED_H_
 
-#include "rt2860_softc.h"
+#include <dev/rt2860/rt2860_softc.h>
 
 #define RT2860_LED_CMD_RADIO_OFF                               0
 #define RT2860_LED_CMD_RADIO_ON                                        (1 << 5)
@@ -30,4 +30,4 @@ void rt2860_led_brightness(struct rt2860_softc *sc, uint8_t 
brightness);
 
 void rt2860_led_cmd(struct rt2860_softc *sc, uint8_t cmd);
 
-#endif /* #ifndef _RT2870_LED_H_ */
+#endif /* #ifndef _RT2860_LED_H_ */
diff --git 
a/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_nexus.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_nexus.c
new file mode 100644
index 0000000..73b6081
--- /dev/null
+++ 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_nexus.c
@@ -0,0 +1,93 @@
+
+/*-
+ * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@xxxxxxxxx>
+ * Copyright (c) 2009 Damien Bergamini <damien.bergamini@xxxxxxx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dev/rt2860/rt2860_softc.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_ucode.h>
+#include <dev/rt2860/rt2860_txwi.h>
+#include <dev/rt2860/rt2860_rxwi.h>
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_read_eeprom.h>
+#include <dev/rt2860/rt2860_led.h>
+#include <dev/rt2860/rt2860_rf.h>
+#include <dev/rt2860/rt2860_debug.h>
+
+/*
+ * Static function prototypes
+ */
+
+static int rt2860_nexus_probe(device_t dev);
+
+static int rt2860_nexus_attach(device_t dev);
+
+int rt2860_attach(device_t dev);
+
+int rt2860_detach(device_t dev);
+
+int rt2860_shutdown(device_t dev);
+
+int rt2860_suspend(device_t dev);
+
+int rt2860_resume(device_t dev);
+
+/*
+ * rt2860_nexus_probe
+ */
+static int rt2860_nexus_probe(device_t dev)
+{
+       device_set_desc(dev, "Ralink RT2860 802.11n MAC/BPP");
+       return 0;
+}
+
+/*
+ * rt2860_nexus_attach
+ */
+static int rt2860_nexus_attach(device_t dev)
+{
+       struct rt2860_softc *sc;
+
+       sc = device_get_softc(dev);
+       sc->mem_rid = 0;
+
+       return (rt2860_attach(dev));
+}
+
+static device_method_t rt2860_nexus_dev_methods[] =
+{
+       DEVMETHOD(device_probe, rt2860_nexus_probe),
+       DEVMETHOD(device_attach, rt2860_nexus_attach),
+       DEVMETHOD(device_detach, rt2860_detach),
+       DEVMETHOD(device_shutdown, rt2860_shutdown),
+       DEVMETHOD(device_suspend, rt2860_suspend),
+       DEVMETHOD(device_resume, rt2860_resume),
+       { 0, 0 }
+};
+
+static driver_t rt2860_nexus_driver =
+{
+       "rt2860",
+       rt2860_nexus_dev_methods,
+       sizeof(struct rt2860_softc)
+};
+
+static devclass_t rt2860_nexus_dev_class;
+
+DRIVER_MODULE(rt2860, nexus, rt2860_nexus_driver, rt2860_nexus_dev_class, 0, 
0);
+MODULE_DEPEND(rt2860, wlan, 1, 1, 1);
+
diff --git 
a/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_pci.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_pci.c
new file mode 100644
index 0000000..ea08556
--- /dev/null
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_pci.c
@@ -0,0 +1,164 @@
+
+/*-
+ * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@xxxxxxxxx>
+ * Copyright (c) 2009 Damien Bergamini <damien.bergamini@xxxxxxx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dev/rt2860/rt2860_softc.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_ucode.h>
+#include <dev/rt2860/rt2860_txwi.h>
+#include <dev/rt2860/rt2860_rxwi.h>
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_read_eeprom.h>
+#include <dev/rt2860/rt2860_led.h>
+#include <dev/rt2860/rt2860_rf.h>
+#include <dev/rt2860/rt2860_debug.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+/*
+ * Defines and macros
+ */
+
+#define PCI_VENDOR_RALINK                                              0x1814
+#define PCI_PRODUCT_RALINK_RT2860_PCI                  0x0601
+#define PCI_PRODUCT_RALINK_RT2860_PCIe                 0x0681
+#define PCI_PRODUCT_RALINK_RT2760_PCI                  0x0701
+#define PCI_PRODUCT_RALINK_RT2790_PCIe                 0x0781
+#define PCI_PRODUCT_RALINK_RT3090_PCIe                 0x3090
+
+/*
+ * Data structures and types
+ */
+
+struct rt2860_pci_ident
+{
+       uint16_t vendor;
+       uint16_t device;
+       const char *name;
+};
+
+/*
+ * Static function prototypes
+ */
+
+static int rt2860_pci_probe(device_t dev);
+
+static int rt2860_pci_attach(device_t dev);
+
+/*
+ * Bus independed methods
+ */
+
+int rt2860_attach(device_t dev);
+
+int rt2860_detach(device_t dev);
+
+int rt2860_shutdown(device_t dev);
+
+int rt2860_suspend(device_t dev);
+
+int rt2860_resume(device_t dev);
+
+
+/*
+ * Static variables
+ */
+
+static const struct rt2860_pci_ident rt2860_pci_ids[] =
+{
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2860_PCI, "Ralink RT2860 PCI" 
},
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2860_PCIe, "Ralink RT2860 
PCIe" },
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2760_PCI, "Ralink RT2760 PCI" 
},
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2790_PCIe, "Ralink RT2790 
PCIe" },
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT2790_PCIe, "Ralink RT2790 
PCIe" },
+       { PCI_VENDOR_RALINK, PCI_PRODUCT_RALINK_RT3090_PCIe, "Ralink RT3090 
PCIe" },
+       { 0, 0, NULL }
+};
+
+
+/*
+ * rt2860_pci_probe
+ */
+static int rt2860_pci_probe(device_t dev)
+{
+       const struct rt2860_pci_ident *ident;
+
+       for (ident = rt2860_pci_ids; ident->name != NULL; ident++)
+       {
+               if (pci_get_vendor(dev) == ident->vendor &&
+                       pci_get_device(dev) == ident->device)
+               {
+                       device_set_desc(dev, ident->name);
+                       return 0;
+               }
+       }
+
+       return ENXIO;
+}
+
+/*
+ * rt2860_pci_attach
+ */
+static int rt2860_pci_attach(device_t dev)
+{
+       struct rt2860_softc *sc;
+
+       sc = device_get_softc(dev);
+
+       if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0)
+       {
+               printf("%s: chip is in D%d power mode, setting to D0\n",
+                       device_get_nameunit(dev), pci_get_powerstate(dev));
+               pci_set_powerstate(dev, PCI_POWERSTATE_D0);
+       }
+
+       /* enable bus-mastering */
+       pci_enable_busmaster(dev);
+       sc->mem_rid = PCIR_BAR(0);
+
+       return (rt2860_attach(dev));
+}
+
+static device_method_t rt2860_pci_dev_methods[] =
+{
+       /* PCI only */
+       DEVMETHOD(device_probe, rt2860_pci_probe),
+       DEVMETHOD(device_attach, rt2860_pci_attach),
+
+       /* Any bus */
+       DEVMETHOD(device_detach, rt2860_detach),
+       DEVMETHOD(device_shutdown, rt2860_shutdown),
+       DEVMETHOD(device_suspend, rt2860_suspend),
+       DEVMETHOD(device_resume, rt2860_resume),
+       { 0, 0 }
+};
+
+static driver_t rt2860_pci_driver =
+{
+       "rt2860",
+       rt2860_pci_dev_methods,
+       sizeof(struct rt2860_softc)
+};
+
+static devclass_t rt2860_pci_dev_class;
+
+DRIVER_MODULE(rt2860, pci, rt2860_pci_driver, rt2860_pci_dev_class, 0, 0);
+MODULE_DEPEND(rt2860, pci, 1, 1, 1);
+MODULE_DEPEND(rt2860, wlan, 1, 1, 1);
+
diff --git 
a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.c
similarity index 91%
rename from 
src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.c
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.c
index 55ad361..4fb4cdd 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.c
+++ 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.c
@@ -16,11 +16,11 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "rt2860_read_eeprom.h"
-#include "rt2860_reg.h"
-#include "rt2860_eeprom.h"
-#include "rt2860_io.h"
-#include "rt2860_debug.h"
+#include <dev/rt2860/rt2860_read_eeprom.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_debug.h>
 
 /*
  * rt2860_read_eeprom
@@ -102,6 +102,8 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
                device_get_nameunit(sc->dev), sc->rf_rev, sc->ntxpath, 
sc->nrxpath);
 
        val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_NIC_CONFIG);
+       if ((val & 0xff00) != 0xff00)
+               sc->patch_dac = (val >> 15) & 1;
 
        sc->hw_radio_cntl = ((val & RT2860_EEPROM_HW_RADIO_CNTL) ? 1 : 0);
        sc->tx_agc_cntl = ((val & RT2860_EEPROM_TX_AGC_CNTL) ? 1 : 0);
@@ -172,8 +174,12 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
        /* read RSSI offsets and LNA gains */
 
        val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_LNA_GAIN);
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000)
+               sc->lna_gain[0] = RT3090_DEF_LNA;
+       else                            /* channel group 0 */
+               sc->lna_gain[0] = val & 0xff;
 
-       sc->lna_gain[0] = (val & 0xff);
+//     sc->lna_gain[0] = (val & 0xff);
        sc->lna_gain[1] = (val >> 8) & 0xff;
 
        val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_2GHZ_BASE);
@@ -181,17 +187,27 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
        sc->rssi_off_2ghz[0] = (val & 0xff);
        sc->rssi_off_2ghz[1] = (val >> 8) & 0xff;
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_2GHZ_BASE + 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_2GHZ_BASE + 2);
 
-       sc->rssi_off_2ghz[2] = (val & 0xff);
+       //sc->rssi_off_2ghz[2] = (val & 0xff);
        sc->lna_gain[2] = (val >> 8) & 0xff;
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000) {
+               /*
+                * On RT3090 chips (limited to 2 Rx chains), this ROM
+                * field contains the Tx mixer gain for the 2GHz band.
+                */
+               if ((val & 0xff) != 0xff)
+                       sc->txmixgain_2ghz = val & 0x7;
+               //DPRINTF(("tx mixer gain=%u (2GHz)\n", sc->txmixgain_2ghz));
+       } else
+               sc->rssi_off_2ghz[2] = val & 0xff;      /* Ant C */
 
        val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_5GHZ_BASE);
 
        sc->rssi_off_5ghz[0] = (val & 0xff);
        sc->rssi_off_5ghz[1] = (val >> 8) & 0xff;
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_5GHZ_BASE + 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_RSSI_OFF_5GHZ_BASE + 2);
 
        sc->rssi_off_5ghz[2] = (val & 0xff);
        sc->lna_gain[3] = (val >> 8) & 0xff;
@@ -378,22 +394,22 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
        sc->tssi_2ghz[0] = (val & 0xff);        /* [-4] */
        sc->tssi_2ghz[1] = (val >> 8);          /* [-3] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 2);
 
        sc->tssi_2ghz[2] = (val & 0xff);        /* [-2] */
        sc->tssi_2ghz[3] = (val >> 8);          /* [-1] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 2 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 2 * 2);
 
        sc->tssi_2ghz[4] = (val & 0xff);        /* [0] */
        sc->tssi_2ghz[5] = (val >> 8);          /* [+1] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 3 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 3 * 2);
 
        sc->tssi_2ghz[6] = (val & 0xff);        /* [+2] */
        sc->tssi_2ghz[7] = (val >> 8);          /* [+3] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 4 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_2GHZ_BASE + 4 * 2);
 
        sc->tssi_2ghz[8] = (val & 0xff);        /* [+4] */
        sc->tssi_step_2ghz = (val >> 8);
@@ -415,22 +431,22 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
        sc->tssi_5ghz[0] = (val & 0xff);        /* [-4] */
        sc->tssi_5ghz[1] = (val >> 8);          /* [-3] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 2);
 
        sc->tssi_5ghz[2] = (val & 0xff);        /* [-2] */
        sc->tssi_5ghz[3] = (val >> 8);          /* [-1] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 2 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 2 * 2);
 
        sc->tssi_5ghz[4] = (val & 0xff);        /* [0] */
        sc->tssi_5ghz[5] = (val >> 8);          /* [+1] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 3 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 3 * 2);
 
        sc->tssi_5ghz[6] = (val & 0xff);        /* [+2] */
        sc->tssi_5ghz[7] = (val >> 8);          /* [+3] */
 
-       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 4 * 
sizeof(uint16_t));
+       val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_TSSI_5GHZ_BASE + 4 * 2);
 
        sc->tssi_5ghz[8] = (val & 0xff);        /* [+4] */
        sc->tssi_step_5ghz = (val >> 8);
@@ -450,8 +466,18 @@ void rt2860_read_eeprom(struct rt2860_softc *sc)
        /* read default BBP settings */
 
        rt2860_io_eeprom_read_multi(sc, RT2860_EEPROM_BBP_BASE,
-               sc->bbp_eeprom, RT2860_SOFTC_BBP_EEPROM_COUNT * 
sizeof(uint16_t));
-
+               sc->bbp_eeprom, RT2860_SOFTC_BBP_EEPROM_COUNT * 2);
+
+       if ((sc->mac_rev & 0xffff0000) >= 0x30710000) {
+               /* read vendor RF settings */
+               for (i = 0; i < 10; i++) {
+                       val = rt2860_io_eeprom_read(sc, RT3071_EEPROM_RF_BASE + 
i);
+                       sc->rf[i].val = val & 0xff;
+                       sc->rf[i].reg = val >> 8;
+//                     DPRINTF(("RF%d=0x%02x\n", sc->rf[i].reg,
+//                         sc->rf[i].val));
+               }
+       }
        /* read powersave level */
 
        val = rt2860_io_eeprom_read(sc, RT2860_EEPROM_POWERSAVE_LEVEL);
diff --git 
a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.h
similarity index 96%
rename from 
src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.h
index 46c4982..e24c2d1 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_read_eeprom.h
+++ 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_read_eeprom.h
@@ -19,7 +19,7 @@
 #ifndef _RT2860_READ_EEPROM_H_
 #define _RT2860_READ_EEPROM_H_
 
-#include "rt2860_softc.h"
+#include <dev/rt2860/rt2860_softc.h>
 
 void rt2860_read_eeprom(struct rt2860_softc *sc);
 
diff --git a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_reg.h 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_reg.h
similarity index 72%
rename from src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_reg.h
rename to 
src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_reg.h
index b4d2c98..63ca7b4 100644
--- a/src/add-ons/kernel/drivers/network/wlan/ralink2860/rt2860_reg.h
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_reg.h
@@ -19,7 +19,11 @@
 #ifndef _RT2860_REG_H_
 #define _RT2860_REG_H_
 
-#define RT2860_REG_EEPROM_CSR                                          0x0004
+#define RT2860_REG_PCI_CFG                                     0x0000
+#define RT2860_REG_EEPROM_CSR                                  0x0004
+#define RT2860_REG_PCI_MCU_CSR                                 0x0008
+#define RT2860_REG_PCI_SYS_CSR                                 0x000c
+#define RT2860_REG_PCIE_JTAG                                   0x0010
 
 #define RT2860_REG_SCHDMA_INT_STATUS                           0x0200
 #define RT2860_REG_SCHDMA_INT_MASK                                     0x0204
@@ -40,42 +44,73 @@
 #define RT2860_REG_SCHDMA_TX_MAX_CNT(qid)                      (0x0234 + (qid) 
* 16)
 #define RT2860_REG_SCHDMA_TX_CTX_IDX(qid)                      (0x0238 + (qid) 
* 16)
 #define RT2860_REG_SCHDMA_TX_DTX_IDX(qid)                      (0x023c + (qid) 
* 16)
+#define RT2860_REG_SCHDMA_US_CYC_CNT                           0x02a4
 
 #define RT2860_REG_PBF_SYS_CTRL                                                
0x0400
-#define RT2860_REG_PBF_CFG                                                     
0x0408
+#define RT2860_REG_PBF_HOST_CMD                                                
0x0404
+#define RT2860_REG_PBF_CFG                                             0x0408
 #define RT2860_REG_PBF_MAX_PCNT                                                
0x040c
+#define RT2860_REG_PBF_BUF_CTRL                                                
0x0410
+#define RT2860_REG_PBF_MCU_INT_STA                                     0x0414
+#define RT2860_REG_PBF_MCU_INT_ENA                                     0x0418
+#define RT2860_REG_PBF_TX0Q_IO                                         0x041c
+#define RT2860_REG_PBF_TX1Q_IO                                         0x0420
+#define RT2860_REG_PBF_TX2Q_IO                                         0x0424
+#define RT2860_REG_PBF_RX0Q_IO                                         0x0428
 #define RT2860_REG_PBF_BCN_OFFSET0                                     0x042c
 #define RT2860_REG_PBF_BCN_OFFSET1                                     0x0430
+#define RT2860_REG_PBF_TXRXQ_STA                                       0x0434
 #define RT2860_REG_PBF_TXRXQ_PCNT                                      0x0438
+#define RT2860_REG_PBF_DBG                                             0x043c
+#define RT2860_REG_PBF_CAP_CTRL                                                
0x0440
 
-#define RT2860_REG_MAC_CSR0                                                    
0x1000
-#define RT2860_REG_SYS_CTRL                                                    
0x1004
-#define RT2860_REG_ADDR_DW0                                                    
0x1008
-#define RT2860_REG_ADDR_DW1                                                    
0x100c
+#define RT2872_REG_RF_CSR_CFG                                          0x500
+#define RT2872_REG_RF_SETTING                                          0x504
+#define RT2872_REG_RF_TEST_CONTROL                                     0x508
+
+#define RT2860_REG_MAC_CSR0                                            0x1000
+#define RT2860_REG_SYS_CTRL                                            0x1004
+#define RT2860_REG_ADDR_DW0                                            0x1008
+#define RT2860_REG_ADDR_DW1                                            0x100c
 #define RT2860_REG_BSSID_DW0                                           0x1010
 #define RT2860_REG_BSSID_DW1                                           0x1014
 #define RT2860_REG_MAX_LEN_CFG                                         0x1018
 #define RT2860_REG_BBP_CSR_CFG                                         0x101c
 #define RT2860_REG_RF_CSR_CFG0                                         0x1020
-#define RT2860_REG_LED_CFG                                                     
0x102c
-
-#define RT2860_REG_XIFS_TIME_CFG                       0x1100
+#define RT2860_REG_LED_CFG                                             0x102c
+#define RT2860_REG_AMPDU_MAX_LEN_20M1S                                 0x1030
+#define RT2860_REG_AMPDU_MAX_LEN_20M2S                                 0x1034
+#define RT2860_REG_AMPDU_MAX_LEN_40M1S                                 0x1038
+#define RT2860_REG_AMPDU_MAX_LEN_40M2S                                 0x103c
+#define RT2860_REG_AMPDU_BA_WINSIZE                                    0x1040
+
+#define RT2860_REG_XIFS_TIME_CFG                                       0x1100
 #define RT2860_REG_BKOFF_SLOT_CFG                                      0x1104
+#define RT2860_REG_NAV_TIME_CFG                                                
0x1108
+#define RT2860_REG_CH_TIME_CFG                                         0x110c
+#define RT2860_REG_PBF_LIFE_TIMER                                      0x1110
 #define RT2860_REG_BCN_TIME_CFG                                                
0x1114
+#define RT2860_REG_TBTT_SYNC_CFG                                       0x1118
 #define RT2860_REG_TSF_TIMER_DW0                                       0x111c
 #define RT2860_REG_TSF_TIMER_DW1                                       0x1120
 #define RT2860_REG_TBTT_TIMER                                          0x1124
+#define RT2860_REG_INT_TIMER                                           0x1128
+#define RT2860_REG_INT_TIMER_EN                                                
0x112c
+#define RT2860_REG_CH_IDLE_STA                                         0x1130
 
 #define RT2860_REG_STATUS_CFG                                          0x1200
 #define RT2860_REG_PWR_PIN_CFG                                         0x1204
 #define RT2860_REG_AUTO_WAKEUP_CFG                                     0x1208
 
-#define RT2860_REG_TX_EDCA_AC_CFG(aci)                         (0x1300 + (aci) 
* 4)
+#define RT2860_REG_TX_EDCA_AC_CFG(aci)                                 (0x1300 
+ (aci) * 4)
+#define RT2860_REG_TX_EDCA_TID_AC_MAP                                  0x1310
 #define RT2860_REG_TX_PWR_CFG(ridx)                                    (0x1314 
+ (ridx) * 4)
 #define RT2860_REG_TX_PIN_CFG                                          0x1328
 #define RT2860_REG_TX_BAND_CFG                                         0x132c
 #define RT2860_REG_TX_SW_CFG0                                          0x1330
 #define RT2860_REG_TX_SW_CFG1                                          0x1334
+#define RT2860_REG_TX_SW_CFG2                                          0x1338
+#define RT2860_REG_TX_TXOP_THRES_CFG                                   0x133c
 #define RT2860_REG_TX_TXOP_CTRL_CFG                                    0x1340
 #define RT2860_REG_TX_RTS_CFG                                          0x1344
 #define RT2860_REG_TX_TIMEOUT_CFG                                      0x1348
@@ -91,14 +126,27 @@
 #define RT2860_REG_TX_MM40_PROT_CFG                                    0x1370
 #define RT2860_REG_TX_GF20_PROT_CFG                                    0x1374
 #define RT2860_REG_TX_GF40_PROT_CFG                                    0x1378
+#define RT2860_REG_TX_EXP_CTS_TIME                                     0x137c
 #define RT2860_REG_TX_EXP_ACK_TIME                                     0x1380
 
 #define RT2860_REG_RX_FILTER_CFG                                       0x1400
 #define RT2860_REG_AUTO_RSP_CFG                                                
0x1404
-#define RT2860_REG_LEGACY_BASIC_RATE                           0x1408
+#define RT2860_REG_LEGACY_BASIC_RATE                                   0x1408
 #define RT2860_REG_HT_BASIC_RATE                                       0x140c
+#define RT2860_REG_HT_CTRL_CFG                                         0x1410
+#define RT2860_REG_SIFS_COST_CFG                                       0x1414
+#define RT2860_REG_RX_PARSER_CFG                                       0x1418
 
-#define RT2860_REG_HCCAPSMP_TXOP_HLDR_ET                       0x1608
+#define RT2860_REG_TX_SEC_CNT0                                         0x1500
+#define RT2860_REG_RX_SEC_CNT0                                         0x1504
+#define RT2860_REG_CCMP_FC_MUTE                                                
0x1508
+
+#define RT2860_REG_HCCAPSMP_TXOP_HLDR_ADDR0                            0x1600
+#define RT2860_REG_HCCAPSMP_TXOP_HLDR_ADDR1                            0x1604
+#define RT2860_REG_HCCAPSMP_TXOP_HLDR_ET                               0x1608
+#define RT2860_REG_HCCAPSMP_QOS_CFPOLL_RA_DW0                          0x160c
+#define RT2860_REG_HCCAPSMP_QOS_CFPOLL_A1_DW1                          0x1610
+#define RT2860_REG_HCCAPSMP_QOS_CFPOLL_QC                              0x1614
 
 #define RT2860_REG_RX_STA_CNT0                                         0x1700
 #define RT2860_REG_RX_STA_CNT1                                         0x1704
@@ -116,7 +164,7 @@
 #define RT2860_REG_TX_AGG_CNT5                                         0x1734
 #define RT2860_REG_TX_AGG_CNT6                                         0x1738
 #define RT2860_REG_TX_AGG_CNT7                                         0x173c
-#define RT2860_REG_TXRX_MPDU_DEN_CNT                           0x1740
+#define RT2860_REG_TXRX_MPDU_DEN_CNT                                   0x1740
 
 #define RT2860_REG_WCID(wcid)                                          (0x1800 
+ (wcid) * 8)
 #define RT2860_REG_PKEY(wcid)                                          (0x4000 
+ (wcid) * 32)
@@ -135,6 +183,95 @@
 
 #define RT2860_REG_BEACON_BASE(vap)                                    (0x7800 
+ (vap) * 512)
 
+/* RT3070 registers */
+#define RT3070_RF_CSR_CFG              0x0500
+#define RT3070_EFUSE_CTRL              0x0580
+#define RT3070_EFUSE_DATA0             0x0590
+#define RT3070_EFUSE_DATA1             0x0594
+#define RT3070_EFUSE_DATA2             0x0598
+#define RT3070_EFUSE_DATA3             0x059c
+#define RT3090_OSC_CTRL                        0x05a4
+#define RT3070_LDO_CFG0                        0x05d4
+#define RT3070_GPIO_SWITCH             0x05dc
+
+#define RT3090_AUX_CTRL                        0x010c
+#define RT3070_OPT_14                  0x0114
+
+/* possible flags for register RF_CSR_CFG */
+#define RT3070_RF_KICK         (1 << 17)
+#define RT3070_RF_WRITE                (1 << 16)
+
+/* possible flags for register EFUSE_CTRL */
+#define RT3070_SEL_EFUSE       (1 << 31)
+#define RT3070_EFSROM_KICK     (1 << 30)
+#define RT3070_EFSROM_AIN_MASK 0x03ff0000
+#define RT3070_EFSROM_AIN_SHIFT        16
+#define RT3070_EFSROM_MODE_MASK        0x000000c0
+#define RT3070_EFUSE_AOUT_MASK 0x0000003f
+
+/* possible flags for RT3020 RF register 1 */
+#define RT3070_RF_BLOCK        (1 << 0)
+#define RT3070_RX0_PD  (1 << 2)
+#define RT3070_TX0_PD  (1 << 3)
+#define RT3070_RX1_PD  (1 << 4)
+#define RT3070_TX1_PD  (1 << 5)
+#define RT3070_RX2_PD  (1 << 6)
+#define RT3070_TX2_PD  (1 << 7)
+
+/* possible flags for RT3020 RF register 1 */
+#define RT3070_RF_BLOCK        (1 << 0)
+#define RT3070_RX0_PD  (1 << 2)
+#define RT3070_TX0_PD  (1 << 3)
+#define RT3070_RX1_PD  (1 << 4)
+#define RT3070_TX1_PD  (1 << 5)
+#define RT3070_RX2_PD  (1 << 6)
+#define RT3070_TX2_PD  (1 << 7)
+
+/* possible flags for RT3020 RF register 7 */
+#define RT3070_TUNE    (1 << 0)
+
+/* possible flags for RT3020 RF register 15 */
+#define RT3070_TX_LO2  (1 << 3)
+
+/* possible flags for RT3020 RF register 17 */
+#define RT3070_TX_LO1  (1 << 3)
+
+/* possible flags for RT3020 RF register 20 */
+#define RT3070_RX_LO1  (1 << 3)
+
+/* possible flags for RT3020 RF register 21 */
+#define RT3070_RX_LO2  (1 << 3)
+#define RT3070_RX_CTB  (1 << 7)
+
+/* possible flags for RT3020 RF register 22 */
+#define RT3070_BB_LOOPBACK     (1 << 0)
+
+/* possible flags for RT3053 RF register 1 */
+#define RT3593_VCO     (1 << 0)
+
+/* possible flags for RT3053 RF register 2 */
+#define RT3593_RESCAL  (1 << 7)
+
+/* possible flags for RT3053 RF register 3 */
+#define RT3593_VCOCAL  (1 << 7)
+
+/* possible flags for RT3053 RF register 6 */
+#define RT3593_VCO_IC  (1 << 6)
+
+/* possible flags for RT3053 RF register 20 */
+#define RT3593_LDO_PLL_VC_MASK 0x0e
+#define RT3593_LDO_RF_VC_MASK  0xe0
+
+/* possible flags for RT3053 RF register 22 */
+#define RT3593_CP_IC_MASK      0xe0
+#define RT3593_CP_IC_SHIFT     5
+
+/* possible flags for RT3053 RF register 46 */
+#define RT3593_RX_CTB  (1 << 5)
+
+#define RT3090_DEF_LNA 10
+
+
 #define RT2860_REG_RF_R1                                                       0
 #define RT2860_REG_RF_R2                                                       
1
 #define RT2860_REG_RF_R3                                                       
2
@@ -240,10 +377,23 @@
 #define RT2860_REG_MAC_SRST                                                    
(1 << 0)
 
 /*
+ * RT2872_REG_RF_CSR_CFG flags
+ */
+#define RT2872_REG_RF_CSR_BUSY                                         (1 << 
17)
+#define RT2872_REG_RF_CSR_KICK                                         (1 << 
17)
+#define RT2872_REG_RF_CSR_WRITE                                                
(1 << 16)
+#define RT2872_REG_RF_ID_SHIFT                                         8
+#define RT2872_REG_RF_ID_MASK                                          0x1f
+#define RT2872_REG_RF_VAL_SHIFT                                                0
+#define RT2872_REG_RF_VAL_MASK                                         0xff
+
+/*
  * RT2860_REG_BBP_CSR_CFG flags
  */
-#define RT2860_REG_BBP_RW_MODE_PARALLEL                                (1 << 
19)
+#define RT2860_REG_BBP_RW_MODE_PARALLEL                                        
(1 << 19)
+#define RT2860_REG_BBP_PAR_DUR                                         (1 << 
19)
 #define RT2860_REG_BBP_CSR_BUSY                                                
(1 << 17)
+#define RT2860_REG_BBP_CSR_KICK                                                
(1 << 17)
 #define RT2860_REG_BBP_CSR_READ                                                
(1 << 16)
 #define RT2860_REG_BBP_REG_SHIFT                                       8
 #define RT2860_REG_BBP_REG_MASK                                                
0xff
diff --git 
a/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_rf.c 
b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_rf.c
new file mode 100644
index 0000000..53080b4
--- /dev/null
+++ b/src/add-ons/kernel/drivers/network/wlan/ralink2860/dev/rt2860/rt2860_rf.c
@@ -0,0 +1,1144 @@
+
+/*-
+ * Copyright (c) 2009-2010 Alexander Egorenkov <egorenar@xxxxxxxxx>
+ * Copyright (c) 2009 Damien Bergamini <damien.bergamini@xxxxxxx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <dev/rt2860/rt2860_rf.h>
+#include <dev/rt2860/rt2860_reg.h>
+#include <dev/rt2860/rt2860_eeprom.h>
+#include <dev/rt2860/rt2860_io.h>
+#include <dev/rt2860/rt2860_debug.h>
+
+static void rt2872_rf_set_chan(struct rt2860_softc *sc,        struct 
ieee80211_channel *c);
+
+extern uint8_t rt3052_rf_default[];
+
+/*
+ * Static variables
+ */
+
+static const struct rt2860_rf_prog
+{
+       uint8_t chan;
+       uint32_t r1, r2, r3, r4;
+} rt2860_rf_2850[] =
+{
+       {   1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b },
+       {   2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f },
+       {   3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b },
+       {   4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f },
+       {   5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b },
+       {   6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f },
+       {   7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b },
+       {   8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f },
+       {   9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b },
+       {  10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f },
+       {  11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b },
+       {  12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f },
+       {  13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b },
+       {  14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193 },
+       {  36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3 },
+       {  38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193 },
+       {  40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183 },
+       {  44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3 },
+       {  46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b },
+       {  48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b },
+       {  52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193 },
+       {  54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3 },
+       {  56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b },
+       {  60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183 },
+       {  62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193 },
+       {  64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3 },
+       { 100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783 },
+       { 102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793 },
+       { 104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3 },
+       { 108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193 },
+       { 110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183 },
+       { 112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b },
+       { 116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3 },
+       { 118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193 },
+       { 120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183 },
+       { 124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193 },
+       { 126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b },
+       { 128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3 },
+       { 132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b },
+       { 134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193 },
+       { 136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b },
+       { 140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183 },
+       { 149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7 },
+       { 151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187 },
+       { 153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f },
+       { 157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f },
+       { 159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7 },
+       { 161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187 },
+       { 165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197 },
+       { 184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b },
+       { 188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13 },
+       { 192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b },
+       { 196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23 },
+       { 208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13 },
+       { 212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b },
+       { 216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23 },
+};
+
+static const struct rfprog {
+       uint8_t         chan;
+       uint32_t        r1, r2, r3, r4;
+} rt2860_rf2850[] = {
+       {   1, 0x100bb3, 0x1301e1, 0x05a014, 0x001402 },
+       {   2, 0x100bb3, 0x1301e1, 0x05a014, 0x001407 },
+       {   3, 0x100bb3, 0x1301e2, 0x05a014, 0x001402 },
+       {   4, 0x100bb3, 0x1301e2, 0x05a014, 0x001407 },
+       {   5, 0x100bb3, 0x1301e3, 0x05a014, 0x001402 },
+       {   6, 0x100bb3, 0x1301e3, 0x05a014, 0x001407 },
+       {   7, 0x100bb3, 0x1301e4, 0x05a014, 0x001402 },
+       {   8, 0x100bb3, 0x1301e4, 0x05a014, 0x001407 },
+       {   9, 0x100bb3, 0x1301e5, 0x05a014, 0x001402 },
+       {  10, 0x100bb3, 0x1301e5, 0x05a014, 0x001407 },
+       {  11, 0x100bb3, 0x1301e6, 0x05a014, 0x001402 },
+       {  12, 0x100bb3, 0x1301e6, 0x05a014, 0x001407 },
+       {  13, 0x100bb3, 0x1301e7, 0x05a014, 0x001402 },
+       {  14, 0x100bb3, 0x1301e8, 0x05a014, 0x001404 },
+       {  36, 0x100bb3, 0x130266, 0x056014, 0x001408 },
+       {  38, 0x100bb3, 0x130267, 0x056014, 0x001404 },
+       {  40, 0x100bb2, 0x1301a0, 0x056014, 0x001400 },
+       {  44, 0x100bb2, 0x1301a0, 0x056014, 0x001408 },
+       {  46, 0x100bb2, 0x1301a1, 0x056014, 0x001402 },
+       {  48, 0x100bb2, 0x1301a1, 0x056014, 0x001406 },
+       {  52, 0x100bb2, 0x1301a2, 0x056014, 0x001404 },
+       {  54, 0x100bb2, 0x1301a2, 0x056014, 0x001408 },
+       {  56, 0x100bb2, 0x1301a3, 0x056014, 0x001402 },
+       {  60, 0x100bb2, 0x1301a4, 0x056014, 0x001400 },
+       {  62, 0x100bb2, 0x1301a4, 0x056014, 0x001404 },
+       {  64, 0x100bb2, 0x1301a4, 0x056014, 0x001408 },
+       { 100, 0x100bb2, 0x1301ac, 0x05e014, 0x001400 },
+       { 102, 0x100bb2, 0x1701ac, 0x15e014, 0x001404 },
+       { 104, 0x100bb2, 0x1701ac, 0x15e014, 0x001408 },
+       { 108, 0x100bb3, 0x17028c, 0x15e014, 0x001404 },
+       { 110, 0x100bb3, 0x13028d, 0x05e014, 0x001400 },
+       { 112, 0x100bb3, 0x13028d, 0x05e014, 0x001406 },
+       { 116, 0x100bb3, 0x13028e, 0x05e014, 0x001408 },
+       { 118, 0x100bb3, 0x13028f, 0x05e014, 0x001404 },
+       { 120, 0x100bb1, 0x1300e0, 0x05e014, 0x001400 },
+       { 124, 0x100bb1, 0x1300e0, 0x05e014, 0x001404 },
+       { 126, 0x100bb1, 0x1300e0, 0x05e014, 0x001406 },
+       { 128, 0x100bb1, 0x1300e0, 0x05e014, 0x001408 },
+       { 132, 0x100bb1, 0x1300e1, 0x05e014, 0x001402 },
+       { 134, 0x100bb1, 0x1300e1, 0x05e014, 0x001404 },
+       { 136, 0x100bb1, 0x1300e1, 0x05e014, 0x001406 },
+       { 140, 0x100bb1, 0x1300e2, 0x05e014, 0x001400 },
+       { 149, 0x100bb1, 0x1300e2, 0x05e014, 0x001409 },
+       { 151, 0x100bb1, 0x1300e3, 0x05e014, 0x001401 },
+       { 153, 0x100bb1, 0x1300e3, 0x05e014, 0x001403 },
+       { 157, 0x100bb1, 0x1300e3, 0x05e014, 0x001407 },
+       { 159, 0x100bb1, 0x1300e3, 0x05e014, 0x001409 },
+       { 161, 0x100bb1, 0x1300e4, 0x05e014, 0x001401 },
+       { 165, 0x100bb1, 0x1300e4, 0x05e014, 0x001405 },
+       { 167, 0x100bb1, 0x1300f4, 0x05e014, 0x001407 },
+       { 169, 0x100bb1, 0x1300f4, 0x05e014, 0x001409 },
+       { 171, 0x100bb1, 0x1300f5, 0x05e014, 0x001401 },
+       { 173, 0x100bb1, 0x1300f5, 0x05e014, 0x001403 }
+};
+
+static const struct rt2860_rf_fi3020
+{
+       uint8_t channel, n, r, k;
+} rt2860_rf_fi3020[] =
+{
+       /* 802.11g  */
+       {1,     241,    2,      2},
+       {2,     241,    2,      7},
+       {3,     242,    2,      2},
+       {4,     242,    2,      7},
+       {5,     243,    2,      2},
+       {6,     243,    2,      7},
+       {7,     244,    2,      2},
+       {8,     244,    2,      7},
+       {9,     245,    2,      2},
+       {10,    245,    2,      7},
+       {11,    246,    2,      2},
+       {12,    246,    2,      7},
+       {13,    247,    2,      2},
+       {14,    248,    2,      4},
+
+       /* 802.11 UNI / HyperLan 2 */
+       {36,    0x56,   0,      4},
+       {38,    0x56,   0,      6},
+       {40,    0x56,   0,      8},
+       {44,    0x57,   0,      0},
+       {46,    0x57,   0,      2},
+       {48,    0x57,   0,      4},
+       {52,    0x57,   0,      8},
+       {54,    0x57,   0,      10},
+       {56,    0x58,   0,      0},
+       {60,    0x58,   0,      4},
+       {62,    0x58,   0,      6},
+       {64,    0x58,   0,      8},
+
+       /* 802.11 HyperLan 2 */
+       {100,   0x5b,   0,      8},
+       {102,   0x5b,   0,      10},
+       {104,   0x5c,   0,      0},
+       {108,   0x5c,   0,      4},
+       {110,   0x5c,   0,      6},
+       {112,   0x5c,   0,      8},
+       {116,   0x5d,   0,      0},
+       {118,   0x5d,   0,      2},
+       {120,   0x5d,   0,      4},
+       {124,   0x5d,   0,      8},
+       {126,   0x5d,   0,      10},
+       {128,   0x5e,   0,      0},
+       {132,   0x5e,   0,      4},
+       {134,   0x5e,   0,      6},
+       {136,   0x5e,   0,      8},
+       {140,   0x5f,   0,      0},
+
+       /* 802.11 UNII */
+       {149,   0x5f,   0,      9},
+       {151,   0x5f,   0,      11},
+       {153,   0x60,   0,      1},
+       {157,   0x60,   0,      5},
+       {159,   0x60,   0,      7},
+       {161,   0x60,   0,      9},
+       {165,   0x61,   0,      1},
+       {167,   0x61,   0,      3},
+       {169,   0x61,   0,      5},
+       {171,   0x61,   0,      7},
+       {173,   0x61,   0,      9},
+};
+
+static const struct {
+       uint8_t reg;
+       uint8_t val;
+}  rt3090_def_rf[] = {
+       {  4, 0x40 },
+       {  5, 0x03 },
+       {  6, 0x02 },
+       {  7, 0x70 },
+       {  9, 0x0f },
+       { 10, 0x41 },
+       { 11, 0x21 },
+       { 12, 0x7b },
+       { 14, 0x90 },
+       { 15, 0x58 },
+       { 16, 0xb3 },
+       { 17, 0x92 },
+       { 18, 0x2c },
+       { 19, 0x02 },
+       { 20, 0xba },
+       { 21, 0xdb },
+       { 24, 0x16 },
+       { 25, 0x01 },
+       { 29, 0x1f }
+};
+
+struct {
+       uint8_t n, r, k;
+} rt3090_freqs[] = {
+       { 0xf1, 2,  2 },
+       { 0xf1, 2,  7 },
+       { 0xf2, 2,  2 },
+       { 0xf2, 2,  7 },
+       { 0xf3, 2,  2 },
+       { 0xf3, 2,  7 },
+       { 0xf4, 2,  2 },
+       { 0xf4, 2,  7 },
+       { 0xf5, 2,  2 },
+       { 0xf5, 2,  7 },
+       { 0xf6, 2,  2 },
+       { 0xf6, 2,  7 },
+       { 0xf7, 2,  2 },
+       { 0xf8, 2,  4 },
+       { 0x56, 0,  4 },
+       { 0x56, 0,  6 },
+       { 0x56, 0,  8 },
+       { 0x57, 0,  0 },
+       { 0x57, 0,  2 },
+       { 0x57, 0,  4 },
+       { 0x57, 0,  8 },
+       { 0x57, 0, 10 },
+       { 0x58, 0,  0 },
+       { 0x58, 0,  4 },
+       { 0x58, 0,  6 },
+       { 0x58, 0,  8 },
+       { 0x5b, 0,  8 },
+       { 0x5b, 0, 10 },
+       { 0x5c, 0,  0 },
+       { 0x5c, 0,  4 },
+       { 0x5c, 0,  6 },
+       { 0x5c, 0,  8 },
+       { 0x5d, 0,  0 },
+       { 0x5d, 0,  2 },
+       { 0x5d, 0,  4 },
+       { 0x5d, 0,  8 },
+       { 0x5d, 0, 10 },
+       { 0x5e, 0,  0 },
+       { 0x5e, 0,  4 },
+       { 0x5e, 0,  6 },
+       { 0x5e, 0,  8 },
+       { 0x5f, 0,  0 },
+       { 0x5f, 0,  9 },
+       { 0x5f, 0, 11 },
+       { 0x60, 0,  1 },
+       { 0x60, 0,  5 },
+       { 0x60, 0,  7 },
+       { 0x60, 0,  9 },
+       { 0x61, 0,  1 },
+       { 0x61, 0,  3 },
+       { 0x61, 0,  5 },
+       { 0x61, 0,  7 },
+       { 0x61, 0,  9 }
+};
+
+
+
+uint8_t
+rt3090_rf_read(struct rt2860_softc *sc, uint8_t reg)
+{
+       uint32_t tmp;
+       int ntries;
+
+       for (ntries = 0; ntries < 100; ntries++) {
+               if (!(rt2860_io_mac_read(sc, RT3070_RF_CSR_CFG) & 
RT3070_RF_KICK))
+                       break;
+               DELAY(1);
+       }
+       if (ntries == 100) {
+               device_printf(sc->dev, "could not read RF register\n");
+               return 0xff;
+       }
+       tmp = RT3070_RF_KICK | reg << 8;
+       rt2860_io_mac_write(sc, RT3070_RF_CSR_CFG, tmp);
+
+       for (ntries = 0; ntries < 100; ntries++) {
+               tmp = rt2860_io_mac_read(sc, RT3070_RF_CSR_CFG);
+               if (!(tmp & RT3070_RF_KICK))
+                       break;
+               DELAY(1);
+       }
+       if (ntries == 100) {
+               device_printf(sc->dev, "could not read RF register\n");
+               return 0xff;
+       }
+       return tmp & 0xff;
+}
+
+void
+rt3090_rf_write(struct rt2860_softc *sc, uint8_t reg, uint8_t val)
+{
+       uint32_t tmp;
+       int ntries;
+
+       for (ntries = 0; ntries < 10; ntries++) {
+               if (!(rt2860_io_mac_read(sc, RT3070_RF_CSR_CFG) & 
RT3070_RF_KICK))
+                       break;
+               DELAY(10);
+       }
+       if (ntries == 10) {
+               device_printf(sc->dev, "could not write to RF\n");
+               return;
+       }
+
+       tmp = RT3070_RF_WRITE | RT3070_RF_KICK | reg << 8 | val;
+       rt2860_io_mac_write(sc, RT3070_RF_CSR_CFG, tmp);
+}
+
+/*
+ * rt2860_rf_name
+ */
+const char *rt2860_rf_name(int rf_rev)
+{
+       switch (rf_rev)
+       {
+               case RT2860_EEPROM_RF_2820:
+                       return "RT2820 2.4G 2T3R";
+
+               case RT2860_EEPROM_RF_2850:
+                       return "RT2850 2.4G/5G 2T3R";
+
+               case RT2860_EEPROM_RF_2720:
+                       return "RT2720 2.4G 1T2R";
+
+               case RT2860_EEPROM_RF_2750:
+                       return "RT2750 2.4G/5G 1T2R";
+
+               case RT2860_EEPROM_RF_3020:
+                       return "RT3020 2.4G 1T1R";
+
+               case RT2860_EEPROM_RF_2020:
+                       return "RT2020 2.4G B/G";
+
+               case RT2860_EEPROM_RF_3021:
+                       return "RT3021 2.4G 1T2R";
+
+               case RT2860_EEPROM_RF_3022:
+                       return "RT3022 2.4G 2T2R";
+
+               case RT2860_EEPROM_RF_3052:
+                       return "RT3052 2.4G/5G 2T2R";
+
+               case RT2860_EEPROM_RF_2853:
+                       return "RT2853 2.4G.5G 3T3R";
+
+               case RT2860_EEPROM_RF_3320:
+                       return "RT3320 2.4G 1T1R with PA";
+
+               case RT2860_EEPROM_RF_3322:
+                       return "RT3322 2.4G 2T2R with PA";
+
+               case RT2860_EEPROM_RF_3053:
+                       return "RT3053 2.4G/5G 3T3R";
+
+               default:
+                       return "unknown";
+       }
+}
+
+/*
+ * rt2860_rf_select_chan_group
+ */
+void rt2860_rf_select_chan_group(struct rt2860_softc *sc,
+       struct ieee80211_channel *c)
+{
+       struct ifnet *ifp;
+       struct ieee80211com *ic;
+       int chan, group;
+       uint32_t tmp;
+
+       ifp = sc->ifp;
+       ic = ifp->if_l2com;
+
+       chan = ieee80211_chan2ieee(ic, c);
+       if (chan == 0 || chan == IEEE80211_CHAN_ANY)
+               return;
+
+       if (chan <= 14)
+               group = 0;
+       else if (chan <= 64)
+               group = 1;
+       else if (chan <= 128)
+               group = 2;
+       else
+               group = 3;
+
+       rt2860_io_bbp_write(sc, 62, 0x37 - sc->lna_gain[group]);
+       rt2860_io_bbp_write(sc, 63, 0x37 - sc->lna_gain[group]);
+       rt2860_io_bbp_write(sc, 64, 0x37 - sc->lna_gain[group]);
+       rt2860_io_bbp_write(sc, 86, 0x00);
+
+       if (group == 0)
+       {
+               if (sc->ext_lna_2ghz)
+               {
+                       rt2860_io_bbp_write(sc, 82, 0x62);
+                       rt2860_io_bbp_write(sc, 75, 0x46);
+               }
+               else
+               {
+                       rt2860_io_bbp_write(sc, 82, 0x84);
+                       rt2860_io_bbp_write(sc, 75, 0x50);
+               }
+       }
+       else
+       {
+               rt2860_io_bbp_write(sc, 82, 0xf2);
+
+               if (sc->ext_lna_5ghz)
+                       rt2860_io_bbp_write(sc, 75, 0x46);
+               else
+                       rt2860_io_bbp_write(sc, 75, 0x50);
+       }
+
+       if (group == 0)
+       {
+               tmp = 0x2e + sc->lna_gain[group];
+       }
+       else
+       {
+               if ((ic->ic_flags & IEEE80211_F_SCAN) || 
!IEEE80211_IS_CHAN_HT40(c))
+                       tmp = 0x32 + sc->lna_gain[group] * 5 / 3;
+               else
+                       tmp = 0x3a + sc->lna_gain[group] * 5 / 3;
+       }
+
+       rt2860_io_bbp_write(sc, 66, tmp);
+
+       tmp = RT2860_REG_RFTR_ENABLE |
+               RT2860_REG_TRSW_ENABLE |
+               RT2860_REG_LNA_PE_G1_ENABLE |
+               RT2860_REG_LNA_PE_A1_ENABLE |
+               RT2860_REG_LNA_PE_G0_ENABLE |
+               RT2860_REG_LNA_PE_A0_ENABLE;
+
+       if (group == 0)
+               tmp |= RT2860_REG_PA_PE_G1_ENABLE |
+                       RT2860_REG_PA_PE_G0_ENABLE;
+       else
+               tmp |= RT2860_REG_PA_PE_A1_ENABLE |
+                       RT2860_REG_PA_PE_A0_ENABLE;
+
+       if (sc->ntxpath == 1)
+               tmp &= ~(RT2860_REG_PA_PE_G1_ENABLE | 
RT2860_REG_PA_PE_A1_ENABLE);
+
+       if (sc->nrxpath == 1)
+               tmp &= ~(RT2860_REG_LNA_PE_G1_ENABLE | 
RT2860_REG_LNA_PE_A1_ENABLE);
+
+       rt2860_io_mac_write(sc, RT2860_REG_TX_PIN_CFG, tmp);
+
+       tmp = rt2860_io_mac_read(sc, RT2860_REG_TX_BAND_CFG);
+
+       tmp &= ~(RT2860_REG_TX_BAND_BG | RT2860_REG_TX_BAND_A | 
RT2860_REG_TX_BAND_HT40_ABOVE);
+
+       if (group == 0)
+               tmp |= RT2860_REG_TX_BAND_BG;
+       else
+               tmp |= RT2860_REG_TX_BAND_A;
+
+       /* set central channel position */
+
+       if (IEEE80211_IS_CHAN_HT40U(c))
+               tmp |= RT2860_REG_TX_BAND_HT40_BELOW;
+       else if (IEEE80211_IS_CHAN_HT40D(c))
+               tmp |= RT2860_REG_TX_BAND_HT40_ABOVE;
+       else
+               tmp |= RT2860_REG_TX_BAND_HT40_BELOW;
+
+       rt2860_io_mac_write(sc, RT2860_REG_TX_BAND_CFG, tmp);
+
+       /* set bandwidth (20MHz or 40MHz) */
+
+       tmp = rt2860_io_bbp_read(sc, 4);
+
+       tmp &= ~0x18;
+
+       if (IEEE80211_IS_CHAN_HT40(c))
+               tmp |= 0x10;
+
+       rt2860_io_bbp_write(sc, 4, tmp);
+
+       /* set central channel position */
+
+       tmp = rt2860_io_bbp_read(sc, 3);
+
+       tmp &= ~0x20;
+
+       if (IEEE80211_IS_CHAN_HT40D(c))
+               tmp |= 0x20;
+
+       rt2860_io_bbp_write(sc, 3, tmp);
+
+       if (sc->mac_rev == 0x28600100)
+       {
+               if (!IEEE80211_IS_CHAN_HT40(c))
+               {
+                       rt2860_io_bbp_write(sc, 69, 0x16);
+                       rt2860_io_bbp_write(sc, 70, 0x08);
+                       rt2860_io_bbp_write(sc, 73, 0x12);
+               }
+               else
+               {
+                       rt2860_io_bbp_write(sc, 69, 0x1a);
+                       rt2860_io_bbp_write(sc, 70, 0x0a);
+                       rt2860_io_bbp_write(sc, 73, 0x16);
+               }
+       }
+
+}
+
+void
+rt3090_set_chan(struct rt2860_softc *sc, u_int chan)
+{
+       int8_t txpow1, txpow2;
+       uint8_t rf;
+       int i;
+
+       KASSERT((chan >= 1 && chan <= 14), "RT3090 is 2GHz only");      /* 
RT3090 is 2GHz only */
+
+       /* find the settings for this channel (we know it exists) */
+       for (i = 0; rt2860_rf2850[i].chan != chan; i++);
+
+       /* use Tx power values from EEPROM */
+       txpow1 = sc->txpow1[i];
+       txpow2 = sc->txpow2[i];
+
+       rt3090_rf_write(sc, 2, rt3090_freqs[i].n);
+       rf = rt3090_rf_read(sc, 3);
+       rf = (rf & ~0x0f) | rt3090_freqs[i].k;
+       rt3090_rf_write(sc, 3, rf);
+       rf = rt3090_rf_read(sc, 6);
+       rf = (rf & ~0x03) | rt3090_freqs[i].r;
+       rt3090_rf_write(sc, 6, rf);
+
+       /* set Tx0 power */
+       rf = rt3090_rf_read(sc, 12);
+       rf = (rf & ~0x1f) | txpow1;
+       rt3090_rf_write(sc, 12, rf);
+
+       /* set Tx1 power */
+       rf = rt3090_rf_read(sc, 13);
+       rf = (rf & ~0x1f) | txpow2;
+       rt3090_rf_write(sc, 13, rf);
+
+       rf = rt3090_rf_read(sc, 1);
+       rf &= ~0xfc;
+       if (sc->ntxpath == 1)
+               rf |= RT3070_TX1_PD | RT3070_TX2_PD;
+       else if (sc->ntxpath == 2)
+               rf |= RT3070_TX2_PD;
+       if (sc->nrxpath == 1)
+               rf |= RT3070_RX1_PD | RT3070_RX2_PD;
+       else if (sc->nrxpath == 2)
+               rf |= RT3070_RX2_PD;
+       rt3090_rf_write(sc, 1, rf);
+
+       /* set RF offset */
+       rf = rt3090_rf_read(sc, 23);
+       rf = (rf & ~0x7f) | sc->rf_freq_off;
+       rt3090_rf_write(sc, 23, rf);
+
+       /* program RF filter */
+       rf = rt3090_rf_read(sc, 24);    /* Tx */
+       rf = (rf & ~0x3f) | sc->rf24_20mhz;
+       rt3090_rf_write(sc, 24, rf);
+       rf = rt3090_rf_read(sc, 31);    /* Rx */
+       rf = (rf & ~0x3f) | sc->rf24_20mhz;
+       rt3090_rf_write(sc, 31, rf);
+
+       /* enable RF tuning */
+       rf = rt3090_rf_read(sc, 7);
+       rt3090_rf_write(sc, 7, rf | RT3070_TUNE);
+}
+
+int
+rt3090_rf_init(struct rt2860_softc *sc)
+{
+       uint32_t tmp;
+       uint8_t rf, bbp;
+       int i;
+
+       rf = rt3090_rf_read(sc, 30);
+       /* toggle RF R30 bit 7 */
+       rt3090_rf_write(sc, 30, rf | 0x80);
+       DELAY(1000);
+       rt3090_rf_write(sc, 30, rf & ~0x80);
+
+       tmp = rt2860_io_mac_read(sc, RT3070_LDO_CFG0);
+       tmp &= ~0x1f000000;
+       if (sc->patch_dac && (sc->mac_rev & 0x0000ffff) < 0x0211)
+               tmp |= 0x0d000000;      /* 1.35V */
+       else
+               tmp |= 0x01000000;      /* 1.2V */
+       rt2860_io_mac_write(sc, RT3070_LDO_CFG0, tmp);
+
+       /* patch LNA_PE_G1 */
+       tmp = rt2860_io_mac_read(sc, RT3070_GPIO_SWITCH);
+       rt2860_io_mac_write(sc, RT3070_GPIO_SWITCH, tmp & ~0x20);
+
+       /* initialize RF registers to default value */
+       for (i = 0; i < (sizeof(rt3090_def_rf)/2); i++) {
+               rt3090_rf_write(sc, rt3090_def_rf[i].reg,
+                   rt3090_def_rf[i].val);
+       }
+
+       /* select 20MHz bandwidth */
+       rt3090_rf_write(sc, 31, 0x14);
+
+       rf = rt3090_rf_read(sc, 6);
+       rt3090_rf_write(sc, 6, rf | 0x40);
+
+       if ((sc->mac_rev & 0xffff0000) != 0x35930000) {

[ *** diff truncated: 3766 lines dropped *** ]


############################################################################

Revision:    hrev44070
Commit:      3245d56441da19afcf181faa05b9880e9839825b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3245d56
Author:      czeidler <haiku@xxxxxxxxxxxxxxxxxx>
Date:        Fri Apr 27 04:02:18 2012 UTC

Cleanup POP3 connection code.
* Use the ServerConnection class in POP3 too. This means no #ifdef USE_SSL for 
the connection anymore.
* I remember from the mailing list that there were problems with to many open 
connection using POP3. Thus, if there is an error or nothing to retrieve close 
the connection.

----------------------------------------------------------------------------


Other related posts: