From: Ivo van Doorn <ivdoorn@gmail.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org, rt2400-devel@lists.sourceforge.net
Subject: [PATCH 20/24] rt2x00: Fix channel initialization
Date: Sun, 16 Sep 2007 14:19:29 +0200 [thread overview]
Message-ID: <200709161419.30939.IvDoorn@gmail.com> (raw)
In-Reply-To: <200709161403.11332.IvDoorn@gmail.com>
Move the channel locking code of rt61 and rt73 into a seperate
function since both config_channel and config_txpower have exactly
the same code.
Use the BBP_R3_SMART_MODE define when we are working with the
BBP R3 register. Also optimize the code by removing the if-statement.
The BBP R94 must be initialized during the channel setup as well,
the value depends on the txpower.
Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
---
drivers/net/wireless/rt2x00/rt61pci.c | 104 +++++++++++++++------------------
drivers/net/wireless/rt2x00/rt73usb.c | 104 +++++++++++++++------------------
2 files changed, 94 insertions(+), 114 deletions(-)
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index a2d852f..6baa651 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -452,58 +452,67 @@ static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev,
rt61pci_config_rate(rt2x00dev, rate->val2);
}
-static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
- const int index, const int channel,
- const int txpower)
+static void rt61pci_config_lock_channel(struct rt2x00_dev *rt2x00dev,
+ struct rf_channel *rf,
+ const int txpower)
{
- struct rf_channel reg;
- u8 bbp = 0;
+ u8 r3;
+ u8 r94;
+ u8 smart;
- /*
- * Fill rf_reg structure.
- */
- memcpy(®, &rt2x00dev->spec.channels[index], sizeof(reg));
+ rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
+ rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
- /*
- * Set TXpower.
- */
- rt2x00_set_field32(®.rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
+ smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
+ rt2x00_rf(&rt2x00dev->chip, RF2527));
- /*
- * Set Frequency offset.
- */
- rt2x00_set_field32(®.rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
+ rt61pci_bbp_read(rt2x00dev, 3, &r3);
+ rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
+ rt61pci_bbp_write(rt2x00dev, 3, r3);
+
+ r94 = 6;
+ if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
+ r94 += txpower - MAX_TXPOWER;
+ else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
+ r94 += txpower;
+ rt61pci_bbp_write(rt2x00dev, 94, r94);
- rt61pci_rf_write(rt2x00dev, 1, reg.rf1);
- rt61pci_rf_write(rt2x00dev, 2, reg.rf2);
- rt61pci_rf_write(rt2x00dev, 3, reg.rf3 & ~0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, reg.rf4);
+ rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
+ rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
+ rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
+ rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
udelay(200);
- rt61pci_rf_write(rt2x00dev, 1, reg.rf1);
- rt61pci_rf_write(rt2x00dev, 2, reg.rf2);
- rt61pci_rf_write(rt2x00dev, 3, reg.rf3 | 0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, reg.rf4);
+ rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
+ rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
+ rt61pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
+ rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
udelay(200);
- rt61pci_rf_write(rt2x00dev, 1, reg.rf1);
- rt61pci_rf_write(rt2x00dev, 2, reg.rf2);
- rt61pci_rf_write(rt2x00dev, 3, reg.rf3 & ~0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, reg.rf4);
-
- rt61pci_bbp_read(rt2x00dev, 3, &bbp);
- if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
- rt2x00_rf(&rt2x00dev->chip, RF2527))
- bbp &= ~0x01;
- else
- bbp |= 0x01;
- rt61pci_bbp_write(rt2x00dev, 3, bbp);
+ rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
+ rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
+ rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
+ rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
msleep(1);
}
+static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
+ const int index, const int channel,
+ const int txpower)
+{
+ struct rf_channel rf;
+
+ /*
+ * Fill rf_reg structure.
+ */
+ memcpy(&rf, &rt2x00dev->spec.channels[index], sizeof(rf));
+
+ rt61pci_config_lock_channel(rt2x00dev, &rf, txpower);
+}
+
static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
const int txpower)
{
@@ -514,26 +523,7 @@ static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
- rt2x00_set_field32(&rf.rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
-
- rt61pci_rf_write(rt2x00dev, 1, rf.rf1);
- rt61pci_rf_write(rt2x00dev, 2, rf.rf2);
- rt61pci_rf_write(rt2x00dev, 3, rf.rf3 & ~0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, rf.rf4);
-
- udelay(200);
-
- rt61pci_rf_write(rt2x00dev, 1, rf.rf1);
- rt61pci_rf_write(rt2x00dev, 2, rf.rf2);
- rt61pci_rf_write(rt2x00dev, 3, rf.rf3 | 0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, rf.rf4);
-
- udelay(200);
-
- rt61pci_rf_write(rt2x00dev, 1, rf.rf1);
- rt61pci_rf_write(rt2x00dev, 2, rf.rf2);
- rt61pci_rf_write(rt2x00dev, 3, rf.rf3 & ~0x00000004);
- rt61pci_rf_write(rt2x00dev, 4, rf.rf4);
+ rt61pci_config_lock_channel(rt2x00dev, &rf, txpower);
}
static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 67a6644..f7017a8 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -428,52 +428,61 @@ static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
rt73usb_config_rate(rt2x00dev, rate->val2);
}
+static void rt73usb_config_lock_channel(struct rt2x00_dev *rt2x00dev,
+ struct rf_channel *rf,
+ const int txpower)
+{
+ u8 r3;
+ u8 r94;
+ u8 smart;
+
+ rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
+ rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
+
+ smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
+ rt2x00_rf(&rt2x00dev->chip, RF2527));
+
+ rt73usb_bbp_read(rt2x00dev, 3, &r3);
+ rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
+ rt73usb_bbp_write(rt2x00dev, 3, r3);
+
+ r94 = 6;
+ if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
+ r94 += txpower - MAX_TXPOWER;
+ else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
+ r94 += txpower;
+ rt73usb_bbp_write(rt2x00dev, 94, r94);
+
+ rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
+ rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
+ rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
+ rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
+
+ rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
+ rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
+ rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
+ rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
+
+ rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
+ rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
+ rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
+ rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
+
+ udelay(10);
+}
+
static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
const int index, const int channel,
const int txpower)
{
- struct rf_channel reg;
- u8 bbp = 0;
+ struct rf_channel rf;
/*
* Fill rf_reg structure.
*/
- memcpy(®, &rt2x00dev->spec.channels[index], sizeof(reg));
+ memcpy(&rf, &rt2x00dev->spec.channels[index], sizeof(rf));
- /*
- * Set TXpower.
- */
- rt2x00_set_field32(®.rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
-
- /*
- * Set Frequency offset.
- */
- rt2x00_set_field32(®.rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
-
- rt73usb_bbp_read(rt2x00dev, 3, &bbp);
- if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
- rt2x00_rf(&rt2x00dev->chip, RF2527))
- bbp &= ~0x01;
- else
- bbp |= 0x01;
- rt73usb_bbp_write(rt2x00dev, 3, bbp);
-
- rt73usb_rf_write(rt2x00dev, 1, reg.rf1);
- rt73usb_rf_write(rt2x00dev, 2, reg.rf2);
- rt73usb_rf_write(rt2x00dev, 3, reg.rf3 & ~0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, reg.rf4);
-
- rt73usb_rf_write(rt2x00dev, 1, reg.rf1);
- rt73usb_rf_write(rt2x00dev, 2, reg.rf2);
- rt73usb_rf_write(rt2x00dev, 3, reg.rf3 | 0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, reg.rf4);
-
- rt73usb_rf_write(rt2x00dev, 1, reg.rf1);
- rt73usb_rf_write(rt2x00dev, 2, reg.rf2);
- rt73usb_rf_write(rt2x00dev, 3, reg.rf3 & ~0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, reg.rf4);
-
- msleep(1);
+ rt73usb_config_lock_channel(rt2x00dev, &rf, txpower);
}
static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
@@ -486,26 +495,7 @@ static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
- rt2x00_set_field32(&rf.rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
-
- rt73usb_rf_write(rt2x00dev, 1, rf.rf1);
- rt73usb_rf_write(rt2x00dev, 2, rf.rf2);
- rt73usb_rf_write(rt2x00dev, 3, rf.rf3 & ~0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, rf.rf4);
-
- udelay(200);
-
- rt73usb_rf_write(rt2x00dev, 1, rf.rf1);
- rt73usb_rf_write(rt2x00dev, 2, rf.rf2);
- rt73usb_rf_write(rt2x00dev, 3, rf.rf3 | 0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, rf.rf4);
-
- udelay(200);
-
- rt73usb_rf_write(rt2x00dev, 1, rf.rf1);
- rt73usb_rf_write(rt2x00dev, 2, rf.rf2);
- rt73usb_rf_write(rt2x00dev, 3, rf.rf3 & ~0x00000004);
- rt73usb_rf_write(rt2x00dev, 4, rf.rf4);
+ rt73usb_config_lock_channel(rt2x00dev, &rf, txpower);
}
static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
--
1.5.3
next prev parent reply other threads:[~2007-09-16 12:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200709161403.11332.IvDoorn@gmail.com>
2007-09-16 12:17 ` [PATCH 1/24] rt2x00: Remove firmware not-NULL check Ivo van Doorn
2007-09-16 12:17 ` [PATCH 2/24] rt2x00: Don't check for IEEE80211_TXCTL_REQ_TX_STATUS Ivo van Doorn
2007-09-16 12:18 ` [PATCH 3/24] rt2x00: Cleanup rxdone Ivo van Doorn
2007-09-16 12:18 ` [PATCH 4/24] rt2x00: Don't allow configuration calls when uninitialized Ivo van Doorn
2007-09-16 12:18 ` [PATCH 5/24] rt2x00: Fix rt61pci and rt73usb beacon handling Ivo van Doorn
2007-09-16 12:18 ` [PATCH 6/24] rt2x00: Recalculate link quality Ivo van Doorn
2007-09-16 12:18 ` [PATCH 7/24] rt2x00: Cleanup entry->flags Ivo van Doorn
2007-09-16 12:18 ` [PATCH 8/24] rt2x00: Reduce LNA flags Ivo van Doorn
2007-09-16 12:18 ` [PATCH 9/24] rt2x00: Rework RT61 and RT73 Antenna handling Ivo van Doorn
2007-09-16 12:18 ` [PATCH 10/24] rt2x00: Rename DEVICE_SUPPORT_ATIM to REQUIRE_BEACON_RING Ivo van Doorn
2007-09-16 12:18 ` [PATCH 11/24] rt2x00: Remove rt2x00mac_reset() Ivo van Doorn
2007-09-16 12:18 ` [PATCH 12/24] rt2x00: Fix system freeze on device removal Ivo van Doorn
2007-09-16 12:18 ` [PATCH 13/24] rt2x00: Reduce magic value writing to device Ivo van Doorn
2007-09-16 12:19 ` [PATCH 14/24] rt2x00: New USB ID's for rt73usb and rt2500usb Ivo van Doorn
2007-09-16 12:19 ` [PATCH 15/24] rt2x00: Beacon ring entries should have QID_MGMT Ivo van Doorn
2007-09-16 12:19 ` [PATCH 16/24] rt2x00: Fix DEV_RATEBIT_ definitions Ivo van Doorn
2007-09-16 12:19 ` [PATCH 17/24] rt2x00: Fix rfkill handling Ivo van Doorn
2007-09-16 12:19 ` [PATCH 18/24] rt2x00: Merge allocation/free register components Ivo van Doorn
2007-09-16 12:19 ` [PATCH 19/24] rt2x00: macro's shouldn't use hidden arguments Ivo van Doorn
2007-09-16 12:19 ` Ivo van Doorn [this message]
2007-09-16 12:19 ` [PATCH 21/24] rt2x00: Add better CONFIG_PM checks Ivo van Doorn
2007-09-16 12:19 ` [PATCH 22/24] rt2x00: Add start/stop handlers Ivo van Doorn
2007-09-16 12:19 ` [PATCH 23/24] rt2x00: Add additional bit to MAX_FRAME_UNIT Ivo van Doorn
2007-09-16 12:19 ` [PATCH 24/24] rt2x00: Release rt2x00 2.0.8 Ivo van Doorn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200709161419.30939.IvDoorn@gmail.com \
--to=ivdoorn@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=rt2400-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.