Skip to contentSkip to conversation

b43: N-PHY: add b43_nphy_rx_iq_est and b43_nphy_tx_iq_workaround

PATCH Superseded Rafał Miłecki 2 participants 4 messages Jan 12, 2010 – Jan 13, 2010 Networking drivers (wireless)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 b43: N-PHY: add b43_nphy_rx_iq_est and b43_nphy_tx_iq_workaround

---
 drivers/net/wireless/b43/phy_n.c |   59 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 1 deletions(-)
drivers/net/wireless/b43/phy_n.c +58 -1
index c244ddf..7b2468d 100644
@@ -31,6 +31,8 @@
 
 
 struct nphy_txgains { u16 txgm[2]; u16 pga[2]; u16 pad[2]; u16 ipa[2]; };
+struct nphy_iq_est { s32 iq0_prod; u32 i0_pwr; u32 q0_pwr; s32 iq1_prod;
+			u32 i1_pwr; u32 q1_pwr; };
 
 void b43_nphy_set_rxantenna(struct b43_wldev *dev, int antenna)
 {//TODO
@@ -471,6 +473,61 @@ static void b43_nphy_rx_iq_coeffs(struct b43_wldev *dev, bool write,
 	}
 }
 
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxIqEst */
+static void b43_nphy_rx_iq_est(struct b43_wldev *dev, struct nphy_iq_est *est,
+				u16 samps, u8 time, bool wait)
+{
+	int i;
+	u16 tmp;
+
+	b43_phy_write(dev, B43_NPHY_IQEST_SAMCNT, samps);
+	b43_phy_maskset(dev, B43_NPHY_IQEST_WT, ~B43_NPHY_IQEST_WT_VAL, time);
+	if (wait)
+		b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+	else
+		b43_phy_mask(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+
+	b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_START);
+
+	for (i = 1000; i; i--) {
+		tmp = b43_phy_read(dev, B43_NPHY_IQEST_CMD);
+		if (!(tmp & B43_NPHY_IQEST_CMD_START)) {
+			est->i0_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_IPACC_HI0) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_IPACC_LO0);
+			est->q0_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_QPACC_HI0) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_QPACC_LO0);
+			est->iq0_prod = (b43_phy_read(dev, B43_NPHY_IQEST_IQACC_HI0) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_IQACC_LO0);
+
+			est->i1_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_IPACC_HI1) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_IPACC_LO1);
+			est->q1_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_QPACC_HI1) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_QPACC_LO1);
+			est->iq1_prod = (b43_phy_read(dev, B43_NPHY_IQEST_IQACC_HI1) << 16) |
+					b43_phy_read(dev, B43_NPHY_IQEST_IQACC_LO1);
+			return;
+		}
+		udelay(10);
+	}
+	memset(est, 0, sizeof(*est));
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxIqWar */
+static void b43_nphy_tx_iq_workaround(struct b43_wldev *dev)
+{
+	u16 array[4];
+	int i;
+
+	b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x3C50);
+	for (i = 0; i < 4; i++)
+		array[i] = b43_phy_read(dev, B43_NPHY_TABLE_DATALO);
+
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0700, array[0]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0702, array[1]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0704, array[2]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0706, array[3]);
+}
+
 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxLpFbw */
 static void b43_nphy_tx_lp_fbw(struct b43_wldev *dev)
 {
@@ -1108,7 +1165,7 @@ static void b43_nphy_restore_cal(struct b43_wldev *dev)
 	//TODO: Write an N PHY table with ID 15, length 2, offset 93, width 16 and data from loft
 
 	if (dev->phy.rev < 2)
-		;//TODO: Call N PHY TX IQ Workaround
+		b43_nphy_tx_iq_workaround(dev);
 
 	if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
 		txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_2G;
Signature · 1 line
1.6.4.2
#1 lore raw

drivers/net/wireless/b43/phy_n.c line 35

Quoted 3 lines · On Tuesday 12 January 2010 20:38:07 Rafał Miłecki wrote:
  struct nphy_txgains { u16 txgm[2]; u16 pga[2]; u16 pad[2]; u16 ipa[2]; };
drivers/net/wireless/b43/phy_n.c +2 -0
+struct nphy_iq_est { s32 iq0_prod; u32 i0_pwr; u32 q0_pwr; s32 iq1_prod;
+			u32 i1_pwr; u32 q1_pwr; };

So it seems I didn't notice this earlier, but this violates kernel coding style. Please do a separate patch that converts all structs from
struct foo { a; b; c; };
to

struct foo {
	a;
	b;
	c;
};

drivers/net/wireless/b43/phy_n.c static void b43_nphy_rx_iq_coeffs(struct b43_wldev *dev, bool write, · line 488

Quoted 4 lines
drivers/net/wireless/b43/phy_n.c +4 -0
+	if (wait)
+		b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+	else
+		b43_phy_mask(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);

Looks wrong to me.
Do you want this?

+ if (wait)
+ b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+ else
+ b43_phy_mask(dev, B43_NPHY_IQEST_CMD, ~B43_NPHY_IQEST_CMD_MODE);

Quoted 4 lines
drivers/net/wireless/b43/phy_n.c +4 -0
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxIqWar */
+static void b43_nphy_tx_iq_workaround(struct b43_wldev *dev)
+{
+	u16 array[4];

drivers/net/wireless/b43/phy_n.c static void b43_nphy_rx_iq_coeffs(struct b43_wldev *dev, bool write, · line 528

Quoted 10 lines
drivers/net/wireless/b43/phy_n.c +10 -0
+	int i;
+
+	b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x3C50);
+	for (i = 0; i < 4; i++)
+		array[i] = b43_phy_read(dev, B43_NPHY_TABLE_DATALO);
+
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0700, array[0]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0702, array[1]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0704, array[2]);
+	b43_shm_write16(dev, B43_SHM_SHARED, 0x0706, array[3]);

Do we have some names for the SHM locations?
If not, just do some defines.
#define B43_SHM_SH_NPHY_TXIQW0 0x0700
#define B43_SHM_SH_NPHY_TXIQW1 0x0702
...
in b43.h (next to the other SHM_SH defines)

Signature · 1 line
Greetings, Michael.
#2 lore raw

2010/1/12 Michael Buesch <[email protected]>:

Quoted 5 lines · On Tuesday 12 January 2010 20:38:07 Rafał Miłecki wrote:
Quoted 3 lines

  struct nphy_txgains { u16 txgm[2]; u16 pga[2]; u16 pad[2]; u16 ipa[2]; }; +struct nphy_iq_est { s32 iq0_prod; u32 i0_pwr; u32 q0_pwr; s32 iq1_prod;
+                     u32 i1_pwr; u32 q1_pwr; };

Quoted 9 lines

So it seems I didn't notice this earlier, but this violates kernel coding style. Please do a separate patch that converts all structs from
struct foo { a; b; c; };
to
struct foo {
       a;
       b;
       c;
};

OK, will do.

Quoted 5 lines
Quoted 4 lines

+     if (wait)
+             b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+     else
+             b43_phy_mask(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);

Quoted 7 lines

Looks wrong to me.
Do you want this?

+       if (wait)
+               b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
+       else
+               b43_phy_mask(dev, B43_NPHY_IQEST_CMD, ~B43_NPHY_IQEST_CMD_MODE);

Obviously. Copy&paste... I can changed function name. Thanks for catching :)

Quoted 13 lines
Quoted 13 lines
drivers/net/wireless/b43/phy_n.c +13 -0
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxIqWar */
+static void b43_nphy_tx_iq_workaround(struct b43_wldev *dev)
+{
+     u16 array[4];
+     int i;
+
+     b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x3C50);
+     for (i = 0; i < 4; i++)
+             array[i] = b43_phy_read(dev, B43_NPHY_TABLE_DATALO);
+
+     b43_shm_write16(dev, B43_SHM_SHARED, 0x0700, array[0]);
+     b43_shm_write16(dev, B43_SHM_SHARED, 0x0702, array[1]);
+     b43_shm_write16(dev, B43_SHM_SHARED, 0x0704, array[2]);
Quoted 8 lines
Quoted 1 line

+     b43_shm_write16(dev, B43_SHM_SHARED, 0x0706, array[3]);

Do we have some names for the SHM locations?
If not, just do some defines.
#define B43_SHM_SH_NPHY_TXIQW0  0x0700
#define B43_SHM_SH_NPHY_TXIQW1  0x0702
...
in b43.h (next to the other SHM_SH defines)

Larry, do you have any other/better names?

Signature · 1 line
Rafał
#3 lore raw

W dniu 12 stycznia 2010 23:51 użytkownik Rafał Miłecki

Quoted 16 lines · <[email protected]> napisał:

2010/1/12 Michael Buesch <[email protected]>:

Quoted 5 lines · On Tuesday 12 January 2010 20:38:07 Rafał Miłecki wrote:
Quoted 3 lines

  struct nphy_txgains { u16 txgm[2]; u16 pga[2]; u16 pad[2]; u16 ipa[2]; }; +struct nphy_iq_est { s32 iq0_prod; u32 i0_pwr; u32 q0_pwr; s32 iq1_prod;
+                     u32 i1_pwr; u32 q1_pwr; };

Quoted 9 lines

So it seems I didn't notice this earlier, but this violates kernel coding style. Please do a separate patch that converts all structs from
struct foo { a; b; c; };
to
struct foo {
       a;
       b;
       c;
};

Quoted 1 line

OK, will do.

I'll use separated patch to correct old wrong-styled definitions. No reason to use wrong style when adding new struct with this patch.

Signature · 1 line
Rafał