Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial
[linux-3.10.git] / drivers / net / wireless / b43 / phy_common.c
index 2ebfc7d..07f009f 100644 (file)
@@ -5,7 +5,7 @@
 
   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
   Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
-  Copyright (c) 2005-2008 Michael Buesch <mb@bu3sch.de>
+  Copyright (c) 2005-2008 Michael Buesch <m@bues.ch>
   Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
   Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
 
@@ -31,6 +31,8 @@
 #include "phy_a.h"
 #include "phy_n.h"
 #include "phy_lp.h"
+#include "phy_ht.h"
+#include "phy_lcn.h"
 #include "b43.h"
 #include "main.h"
 
@@ -50,7 +52,7 @@ int b43_phy_allocate(struct b43_wldev *dev)
                phy->ops = &b43_phyops_g;
                break;
        case B43_PHYTYPE_N:
-#ifdef CONFIG_B43_NPHY
+#ifdef CONFIG_B43_PHY_N
                phy->ops = &b43_phyops_n;
 #endif
                break;
@@ -59,6 +61,16 @@ int b43_phy_allocate(struct b43_wldev *dev)
                phy->ops = &b43_phyops_lp;
 #endif
                break;
+       case B43_PHYTYPE_HT:
+#ifdef CONFIG_B43_PHY_HT
+               phy->ops = &b43_phyops_ht;
+#endif
+               break;
+       case B43_PHYTYPE_LCN:
+#ifdef CONFIG_B43_PHY_LCN
+               phy->ops = &b43_phyops_lcn;
+#endif
+               break;
        }
        if (B43_WARN_ON(!phy->ops))
                return -ENODEV;
@@ -84,7 +96,7 @@ int b43_phy_init(struct b43_wldev *dev)
 
        phy->channel = ops->get_default_chan(dev);
 
-       ops->software_rfkill(dev, RFKILL_STATE_UNBLOCKED);
+       ops->software_rfkill(dev, false);
        err = ops->init(dev);
        if (err) {
                b43err(dev->wl, "PHY init failed\n");
@@ -104,7 +116,7 @@ err_phy_exit:
        if (ops->exit)
                ops->exit(dev);
 err_block_rf:
-       ops->software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED);
+       ops->software_rfkill(dev, true);
 
        return err;
 }
@@ -113,7 +125,7 @@ void b43_phy_exit(struct b43_wldev *dev)
 {
        const struct b43_phy_operations *ops = dev->phy.ops;
 
-       ops->software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED);
+       ops->software_rfkill(dev, true);
        if (ops->exit)
                ops->exit(dev);
 }
@@ -131,12 +143,16 @@ void b43_radio_lock(struct b43_wldev *dev)
 {
        u32 macctl;
 
+#if B43_DEBUG
+       B43_WARN_ON(dev->phy.radio_locked);
+       dev->phy.radio_locked = 1;
+#endif
+
        macctl = b43_read32(dev, B43_MMIO_MACCTL);
-       B43_WARN_ON(macctl & B43_MACCTL_RADIOLOCK);
        macctl |= B43_MACCTL_RADIOLOCK;
        b43_write32(dev, B43_MMIO_MACCTL, macctl);
-       /* Commit the write and wait for the device
-        * to exit any radio register access. */
+       /* Commit the write and wait for the firmware
+        * to finish any radio register access. */
        b43_read32(dev, B43_MMIO_MACCTL);
        udelay(10);
 }
@@ -145,11 +161,15 @@ void b43_radio_unlock(struct b43_wldev *dev)
 {
        u32 macctl;
 
+#if B43_DEBUG
+       B43_WARN_ON(!dev->phy.radio_locked);
+       dev->phy.radio_locked = 0;
+#endif
+
        /* Commit any write */
        b43_read16(dev, B43_MMIO_PHY_VER);
        /* unlock */
        macctl = b43_read32(dev, B43_MMIO_MACCTL);
-       B43_WARN_ON(!(macctl & B43_MACCTL_RADIOLOCK));
        macctl &= ~B43_MACCTL_RADIOLOCK;
        b43_write32(dev, B43_MMIO_MACCTL, macctl);
 }
@@ -160,7 +180,7 @@ void b43_phy_lock(struct b43_wldev *dev)
        B43_WARN_ON(dev->phy.phy_locked);
        dev->phy.phy_locked = 1;
 #endif
-       B43_WARN_ON(dev->dev->id.revision < 3);
+       B43_WARN_ON(dev->dev->core_rev < 3);
 
        if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
                b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
@@ -172,7 +192,7 @@ void b43_phy_unlock(struct b43_wldev *dev)
        B43_WARN_ON(!dev->phy.phy_locked);
        dev->phy.phy_locked = 0;
 #endif
-       B43_WARN_ON(dev->dev->id.revision < 3);
+       B43_WARN_ON(dev->dev->core_rev < 3);
 
        if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
                b43_power_saving_ctl_bits(dev, 0);
@@ -223,6 +243,7 @@ void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
 u16 b43_phy_read(struct b43_wldev *dev, u16 reg)
 {
        assert_mac_suspended(dev);
+       dev->phy.writes_counter = 0;
        return dev->phy.ops->phy_read(dev, reg);
 }
 
@@ -230,24 +251,50 @@ void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value)
 {
        assert_mac_suspended(dev);
        dev->phy.ops->phy_write(dev, reg, value);
+       if (++dev->phy.writes_counter == B43_MAX_WRITES_IN_ROW) {
+               b43_read16(dev, B43_MMIO_PHY_VER);
+               dev->phy.writes_counter = 0;
+       }
+}
+
+void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg)
+{
+       assert_mac_suspended(dev);
+       dev->phy.ops->phy_write(dev, destreg,
+               dev->phy.ops->phy_read(dev, srcreg));
 }
 
 void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
 {
-       b43_phy_write(dev, offset,
-                     b43_phy_read(dev, offset) & mask);
+       if (dev->phy.ops->phy_maskset) {
+               assert_mac_suspended(dev);
+               dev->phy.ops->phy_maskset(dev, offset, mask, 0);
+       } else {
+               b43_phy_write(dev, offset,
+                             b43_phy_read(dev, offset) & mask);
+       }
 }
 
 void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set)
 {
-       b43_phy_write(dev, offset,
-                     b43_phy_read(dev, offset) | set);
+       if (dev->phy.ops->phy_maskset) {
+               assert_mac_suspended(dev);
+               dev->phy.ops->phy_maskset(dev, offset, 0xFFFF, set);
+       } else {
+               b43_phy_write(dev, offset,
+                             b43_phy_read(dev, offset) | set);
+       }
 }
 
 void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
 {
-       b43_phy_write(dev, offset,
-                     (b43_phy_read(dev, offset) & mask) | set);
+       if (dev->phy.ops->phy_maskset) {
+               assert_mac_suspended(dev);
+               dev->phy.ops->phy_maskset(dev, offset, mask, set);
+       } else {
+               b43_phy_write(dev, offset,
+                             (b43_phy_read(dev, offset) & mask) | set);
+       }
 }
 
 int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)
@@ -264,8 +311,10 @@ int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)
         */
        channelcookie = new_channel;
        if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
-               channelcookie |= 0x100;
-       //FIXME set 40Mhz flag if required
+               channelcookie |= B43_SHM_SH_CHAN_5GHZ;
+       /* FIXME: set 40Mhz flag if required */
+       if (0)
+               channelcookie |= B43_SHM_SH_CHAN_40MHZ;
        savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN);
        b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
 
@@ -287,17 +336,14 @@ err_restore_cookie:
        return err;
 }
 
-void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state)
+void b43_software_rfkill(struct b43_wldev *dev, bool blocked)
 {
        struct b43_phy *phy = &dev->phy;
 
-       if (state == RFKILL_STATE_HARD_BLOCKED) {
-               /* We cannot hardware-block the device */
-               state = RFKILL_STATE_SOFT_BLOCKED;
-       }
-
-       phy->ops->software_rfkill(dev, state);
-       phy->radio_on = (state == RFKILL_STATE_UNBLOCKED);
+       b43_mac_suspend(dev);
+       phy->ops->software_rfkill(dev, blocked);
+       phy->radio_on = !blocked;
+       b43_mac_enable(dev);
 }
 
 /**
@@ -320,7 +366,6 @@ void b43_phy_txpower_adjust_work(struct work_struct *work)
        mutex_unlock(&wl->mutex);
 }
 
-/* Called with wl->irq_lock locked */
 void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
 {
        struct b43_phy *phy = &dev->phy;
@@ -335,8 +380,8 @@ void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
        /* The next check will be needed in two seconds, or later. */
        phy->next_txpwr_check_time = round_jiffies(now + (HZ * 2));
 
-       if ((dev->dev->bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
-           (dev->dev->bus->boardinfo.type == SSB_BOARD_BU4306))
+       if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) &&
+           (dev->dev->board_type == SSB_BOARD_BU4306))
                return; /* No software txpower adjustment needed */
 
        result = phy->ops->recalc_txpower(dev, !!(flags & B43_TXPWR_IGNORE_TSSI));
@@ -347,7 +392,7 @@ void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
 
        /* We must adjust the transmission power in hardware.
         * Schedule b43_phy_txpower_adjust_work(). */
-       queue_work(dev->wl->hw->workqueue, &dev->wl->txpower_adjust_work);
+       ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work);
 }
 
 int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset)
@@ -395,3 +440,57 @@ void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on)
 {
        b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
 }
+
+
+bool b43_channel_type_is_40mhz(enum nl80211_channel_type channel_type)
+{
+       return (channel_type == NL80211_CHAN_HT40MINUS ||
+               channel_type == NL80211_CHAN_HT40PLUS);
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
+struct b43_c32 b43_cordic(int theta)
+{
+       static const u32 arctg[] = {
+               2949120, 1740967, 919879, 466945, 234379, 117304,
+                 58666,   29335,  14668,   7334,   3667,   1833,
+                   917,     458,    229,    115,     57,     29,
+       };
+       u8 i;
+       s32 tmp;
+       s8 signx = 1;
+       u32 angle = 0;
+       struct b43_c32 ret = { .i = 39797, .q = 0, };
+
+       while (theta > (180 << 16))
+               theta -= (360 << 16);
+       while (theta < -(180 << 16))
+               theta += (360 << 16);
+
+       if (theta > (90 << 16)) {
+               theta -= (180 << 16);
+               signx = -1;
+       } else if (theta < -(90 << 16)) {
+               theta += (180 << 16);
+               signx = -1;
+       }
+
+       for (i = 0; i <= 17; i++) {
+               if (theta > angle) {
+                       tmp = ret.i - (ret.q >> i);
+                       ret.q += ret.i >> i;
+                       ret.i = tmp;
+                       angle += arctg[i];
+               } else {
+                       tmp = ret.i + (ret.q >> i);
+                       ret.q -= ret.i >> i;
+                       ret.i = tmp;
+                       angle -= arctg[i];
+               }
+       }
+
+       ret.i *= signx;
+       ret.q *= signx;
+
+       return ret;
+}