]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/net/wireless/b43/phy_n.c
b43: N-PHY: implement calculating IQ gain params
[mv-sheeva.git] / drivers / net / wireless / b43 / phy_n.c
index 0e379427270ad61809ea113db5cab7309be9004c..8a3bc2c58a813316af143318e64acd6c7dfe14aa 100644 (file)
@@ -378,6 +378,28 @@ static void b43_nphy_pa_override(struct b43_wldev *dev, bool enable)
        }
 }
 
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxLpFbw */
+static void b43_nphy_tx_lp_fbw(struct b43_wldev *dev)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+       u16 tmp;
+       enum ieee80211_band band = b43_current_band(dev->wl);
+       bool ipa = (nphy->ipa2g_on && band == IEEE80211_BAND_2GHZ) ||
+                       (nphy->ipa5g_on && band == IEEE80211_BAND_5GHZ);
+
+       if (dev->phy.rev >= 3) {
+               if (ipa) {
+                       tmp = 4;
+                       b43_phy_write(dev, B43_NPHY_TXF_40CO_B32S2,
+                             (((((tmp << 3) | tmp) << 3) | tmp) << 3) | tmp);
+               }
+
+               tmp = 1;
+               b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S2,
+                             (((((tmp << 3) | tmp) << 3) | tmp) << 3) | tmp);
+       }
+}
+
 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */
 static void b43_nphy_bmac_clock_fgc(struct b43_wldev *dev, bool force)
 {
@@ -408,6 +430,177 @@ static void b43_nphy_reset_cca(struct b43_wldev *dev)
        /* TODO: N PHY Force RF Seq with argument 2 */
 }
 
+/* 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/RxIqCoeffs */
+static void b43_nphy_rx_iq_coeffs(struct b43_wldev *dev, bool write,
+                                       struct b43_phy_n_iq_comp *pcomp)
+{
+       if (write) {
+               b43_phy_write(dev, B43_NPHY_C1_RXIQ_COMPA0, pcomp->a0);
+               b43_phy_write(dev, B43_NPHY_C1_RXIQ_COMPB0, pcomp->b0);
+               b43_phy_write(dev, B43_NPHY_C2_RXIQ_COMPA1, pcomp->a1);
+               b43_phy_write(dev, B43_NPHY_C2_RXIQ_COMPB1, pcomp->b1);
+       } else {
+               pcomp->a0 = b43_phy_read(dev, B43_NPHY_C1_RXIQ_COMPA0);
+               pcomp->b0 = b43_phy_read(dev, B43_NPHY_C1_RXIQ_COMPB0);
+               pcomp->a1 = b43_phy_read(dev, B43_NPHY_C2_RXIQ_COMPA1);
+               pcomp->b1 = b43_phy_read(dev, B43_NPHY_C2_RXIQ_COMPB1);
+       }
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalcRxIqComp */
+static void b43_nphy_calc_rx_iq_comp(struct b43_wldev *dev, u8 mask)
+{
+       int i;
+       s32 iq;
+       u32 ii;
+       u32 qq;
+       int iq_nbits, qq_nbits;
+       int arsh, brsh;
+       u16 tmp, a, b;
+
+       struct nphy_iq_est est;
+       struct b43_phy_n_iq_comp old;
+       struct b43_phy_n_iq_comp new = { };
+       bool error = false;
+
+       if (mask == 0)
+               return;
+
+       b43_nphy_rx_iq_coeffs(dev, false, &old);
+       b43_nphy_rx_iq_coeffs(dev, true, &new);
+       b43_nphy_rx_iq_est(dev, &est, 0x4000, 32, false);
+       new = old;
+
+       for (i = 0; i < 2; i++) {
+               if (i == 0 && (mask & 1)) {
+                       iq = est.iq0_prod;
+                       ii = est.i0_pwr;
+                       qq = est.q0_pwr;
+               } else if (i == 1 && (mask & 2)) {
+                       iq = est.iq1_prod;
+                       ii = est.i1_pwr;
+                       qq = est.q1_pwr;
+               } else {
+                       B43_WARN_ON(1);
+                       continue;
+               }
+
+               if (ii + qq < 2) {
+                       error = true;
+                       break;
+               }
+
+               iq_nbits = fls(abs(iq));
+               qq_nbits = fls(qq);
+
+               arsh = iq_nbits - 20;
+               if (arsh >= 0) {
+                       a = -((iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
+                       tmp = ii >> arsh;
+               } else {
+                       a = -((iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
+                       tmp = ii << -arsh;
+               }
+               if (tmp == 0) {
+                       error = true;
+                       break;
+               }
+               a /= tmp;
+
+               brsh = qq_nbits - 11;
+               if (brsh >= 0) {
+                       b = (qq << (31 - qq_nbits));
+                       tmp = ii >> brsh;
+               } else {
+                       b = (qq << (31 - qq_nbits));
+                       tmp = ii << -brsh;
+               }
+               if (tmp == 0) {
+                       error = true;
+                       break;
+               }
+               b = int_sqrt(b / tmp - a * a) - (1 << 10);
+
+               if (i == 0 && (mask & 0x1)) {
+                       if (dev->phy.rev >= 3) {
+                               new.a0 = a & 0x3FF;
+                               new.b0 = b & 0x3FF;
+                       } else {
+                               new.a0 = b & 0x3FF;
+                               new.b0 = a & 0x3FF;
+                       }
+               } else if (i == 1 && (mask & 0x2)) {
+                       if (dev->phy.rev >= 3) {
+                               new.a1 = a & 0x3FF;
+                               new.b1 = b & 0x3FF;
+                       } else {
+                               new.a1 = b & 0x3FF;
+                               new.b1 = a & 0x3FF;
+                       }
+               }
+       }
+
+       if (error)
+               new = old;
+
+       b43_nphy_rx_iq_coeffs(dev, true, &new);
+}
+
+/* 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, B43_SHM_SH_NPHY_TXIQW0, array[0]);
+       b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW1, array[1]);
+       b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW2, array[2]);
+       b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW3, array[3]);
+}
+
 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/clip-detection */
 static void b43_nphy_write_clip_detection(struct b43_wldev *dev, u16 *clip_st)
 {
@@ -443,6 +636,29 @@ static u16 b43_nphy_classifier(struct b43_wldev *dev, u16 mask, u16 val)
        return tmp;
 }
 
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/carriersearch */
+static void b43_nphy_stay_in_carrier_search(struct b43_wldev *dev, bool enable)
+{
+       struct b43_phy *phy = &dev->phy;
+       struct b43_phy_n *nphy = phy->n;
+
+       if (enable) {
+               u16 clip[] = { 0xFFFF, 0xFFFF };
+               if (nphy->deaf_count++ == 0) {
+                       nphy->classifier_state = b43_nphy_classifier(dev, 0, 0);
+                       b43_nphy_classifier(dev, 0x7, 0);
+                       b43_nphy_read_clip_detection(dev, nphy->clip_state);
+                       b43_nphy_write_clip_detection(dev, clip);
+               }
+               b43_nphy_reset_cca(dev);
+       } else {
+               if (--nphy->deaf_count == 0) {
+                       b43_nphy_classifier(dev, 0x7, nphy->classifier_state);
+                       b43_nphy_write_clip_detection(dev, nphy->clip_state);
+               }
+       }
+}
+
 enum b43_nphy_rf_sequence {
        B43_RFSEQ_RX2TX,
        B43_RFSEQ_TX2RX,
@@ -896,6 +1112,328 @@ static void b43_nphy_rssi_cal(struct b43_wldev *dev)
        }
 }
 
+/*
+ * Restore RSSI Calibration
+ * http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreRssiCal
+ */
+static void b43_nphy_restore_rssi_cal(struct b43_wldev *dev)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+
+       u16 *rssical_radio_regs = NULL;
+       u16 *rssical_phy_regs = NULL;
+
+       if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
+               if (!nphy->rssical_chanspec_2G)
+                       return;
+               rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_2G;
+               rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_2G;
+       } else {
+               if (!nphy->rssical_chanspec_5G)
+                       return;
+               rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_5G;
+               rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_5G;
+       }
+
+       /* TODO use some definitions */
+       b43_radio_maskset(dev, 0x602B, 0xE3, rssical_radio_regs[0]);
+       b43_radio_maskset(dev, 0x702B, 0xE3, rssical_radio_regs[1]);
+
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Z, rssical_phy_regs[0]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Z, rssical_phy_regs[1]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Z, rssical_phy_regs[2]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Z, rssical_phy_regs[3]);
+
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_X, rssical_phy_regs[4]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_X, rssical_phy_regs[5]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_X, rssical_phy_regs[6]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_X, rssical_phy_regs[7]);
+
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Y, rssical_phy_regs[8]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Y, rssical_phy_regs[9]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Y, rssical_phy_regs[10]);
+       b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Y, rssical_phy_regs[11]);
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GetIpaGainTbl */
+static const u32 *b43_nphy_get_ipa_gain_table(struct b43_wldev *dev)
+{
+       if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
+               if (dev->phy.rev >= 6) {
+                       /* TODO If the chip is 47162
+                               return txpwrctrl_tx_gain_ipa_rev5 */
+                       return txpwrctrl_tx_gain_ipa_rev6;
+               } else if (dev->phy.rev >= 5) {
+                       return txpwrctrl_tx_gain_ipa_rev5;
+               } else {
+                       return txpwrctrl_tx_gain_ipa;
+               }
+       } else {
+               return txpwrctrl_tx_gain_ipa_5g;
+       }
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalRadioSetup */
+static void b43_nphy_tx_cal_radio_setup(struct b43_wldev *dev)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+       u16 *save = nphy->tx_rx_cal_radio_saveregs;
+
+       if (dev->phy.rev >= 3) {
+               /* TODO */
+       } else {
+               save[0] = b43_radio_read16(dev, B2055_C1_TX_RF_IQCAL1);
+               b43_radio_write16(dev, B2055_C1_TX_RF_IQCAL1, 0x29);
+
+               save[1] = b43_radio_read16(dev, B2055_C1_TX_RF_IQCAL2);
+               b43_radio_write16(dev, B2055_C1_TX_RF_IQCAL2, 0x54);
+
+               save[2] = b43_radio_read16(dev, B2055_C2_TX_RF_IQCAL1);
+               b43_radio_write16(dev, B2055_C2_TX_RF_IQCAL1, 0x29);
+
+               save[3] = b43_radio_read16(dev, B2055_C2_TX_RF_IQCAL2);
+               b43_radio_write16(dev, B2055_C2_TX_RF_IQCAL2, 0x54);
+
+               save[3] = b43_radio_read16(dev, B2055_C1_PWRDET_RXTX);
+               save[4] = b43_radio_read16(dev, B2055_C2_PWRDET_RXTX);
+
+               if (!(b43_phy_read(dev, B43_NPHY_BANDCTL) &
+                   B43_NPHY_BANDCTL_5GHZ)) {
+                       b43_radio_write16(dev, B2055_C1_PWRDET_RXTX, 0x04);
+                       b43_radio_write16(dev, B2055_C2_PWRDET_RXTX, 0x04);
+               } else {
+                       b43_radio_write16(dev, B2055_C1_PWRDET_RXTX, 0x20);
+                       b43_radio_write16(dev, B2055_C2_PWRDET_RXTX, 0x20);
+               }
+
+               if (dev->phy.rev < 2) {
+                       b43_radio_set(dev, B2055_C1_TX_BB_MXGM, 0x20);
+                       b43_radio_set(dev, B2055_C2_TX_BB_MXGM, 0x20);
+               } else {
+                       b43_radio_mask(dev, B2055_C1_TX_BB_MXGM, ~0x20);
+                       b43_radio_mask(dev, B2055_C2_TX_BB_MXGM, ~0x20);
+               }
+       }
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/IqCalGainParams */
+static void b43_nphy_iq_cal_gain_params(struct b43_wldev *dev, u16 core,
+                                       struct nphy_txgains target,
+                                       struct nphy_iqcal_params *params)
+{
+       int i, j, indx;
+       u16 gain;
+
+       if (dev->phy.rev >= 3) {
+               params->txgm = target.txgm[core];
+               params->pga = target.pga[core];
+               params->pad = target.pad[core];
+               params->ipa = target.ipa[core];
+               params->cal_gain = (params->txgm << 12) | (params->pga << 8) |
+                                       (params->pad << 4) | (params->ipa);
+               for (j = 0; j < 5; j++)
+                       params->ncorr[j] = 0x79;
+       } else {
+               gain = (target.pad[core]) | (target.pga[core] << 4) |
+                       (target.txgm[core] << 8);
+
+               indx = (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ) ?
+                       1 : 0;
+               for (i = 0; i < 9; i++)
+                       if (tbl_iqcal_gainparams[indx][i][0] == gain)
+                               break;
+               i = min(i, 8);
+
+               params->txgm = tbl_iqcal_gainparams[indx][i][1];
+               params->pga = tbl_iqcal_gainparams[indx][i][2];
+               params->pad = tbl_iqcal_gainparams[indx][i][3];
+               params->cal_gain = (params->txgm << 7) | (params->pga << 4) |
+                                       (params->pad << 2);
+               for (j = 0; j < 4; j++)
+                       params->ncorr[j] = tbl_iqcal_gainparams[indx][i][4 + j];
+       }
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/UpdateTxCalLadder */
+static void b43_nphy_update_tx_cal_ladder(struct b43_wldev *dev, u16 core)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+       int i;
+       u16 scale, entry;
+
+       u16 tmp = nphy->txcal_bbmult;
+       if (core == 0)
+               tmp >>= 8;
+       tmp &= 0xff;
+
+       for (i = 0; i < 18; i++) {
+               scale = (ladder_lo[i].percent * tmp) / 100;
+               entry = ((scale & 0xFF) << 8) | ladder_lo[i].g_env;
+               /* TODO: Write an N PHY Table with ID 15, length 1,
+                       offset i, width 16, and data entry */
+
+               scale = (ladder_iq[i].percent * tmp) / 100;
+               entry = ((scale & 0xFF) << 8) | ladder_iq[i].g_env;
+               /* TODO: Write an N PHY Table with ID 15, length 1,
+                       offset i + 32, width 16, and data entry */
+       }
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GetTxGain */
+static struct nphy_txgains b43_nphy_get_tx_gains(struct b43_wldev *dev)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+
+       u16 curr_gain[2];
+       struct nphy_txgains target;
+       const u32 *table = NULL;
+
+       if (nphy->txpwrctrl == 0) {
+               int i;
+
+               if (nphy->hang_avoid)
+                       b43_nphy_stay_in_carrier_search(dev, true);
+               /* TODO: Read an N PHY Table with ID 7, length 2,
+                       offset 0x110, width 16, and curr_gain */
+               if (nphy->hang_avoid)
+                       b43_nphy_stay_in_carrier_search(dev, false);
+
+               for (i = 0; i < 2; ++i) {
+                       if (dev->phy.rev >= 3) {
+                               target.ipa[i] = curr_gain[i] & 0x000F;
+                               target.pad[i] = (curr_gain[i] & 0x00F0) >> 4;
+                               target.pga[i] = (curr_gain[i] & 0x0F00) >> 8;
+                               target.txgm[i] = (curr_gain[i] & 0x7000) >> 12;
+                       } else {
+                               target.ipa[i] = curr_gain[i] & 0x0003;
+                               target.pad[i] = (curr_gain[i] & 0x000C) >> 2;
+                               target.pga[i] = (curr_gain[i] & 0x0070) >> 4;
+                               target.txgm[i] = (curr_gain[i] & 0x0380) >> 7;
+                       }
+               }
+       } else {
+               int i;
+               u16 index[2];
+               index[0] = (b43_phy_read(dev, B43_NPHY_C1_TXPCTL_STAT) &
+                       B43_NPHY_TXPCTL_STAT_BIDX) >>
+                       B43_NPHY_TXPCTL_STAT_BIDX_SHIFT;
+               index[1] = (b43_phy_read(dev, B43_NPHY_C2_TXPCTL_STAT) &
+                       B43_NPHY_TXPCTL_STAT_BIDX) >>
+                       B43_NPHY_TXPCTL_STAT_BIDX_SHIFT;
+
+               for (i = 0; i < 2; ++i) {
+                       if (dev->phy.rev >= 3) {
+                               enum ieee80211_band band =
+                                       b43_current_band(dev->wl);
+
+                               if ((nphy->ipa2g_on &&
+                                    band == IEEE80211_BAND_2GHZ) ||
+                                   (nphy->ipa5g_on &&
+                                    band == IEEE80211_BAND_5GHZ)) {
+                                       table = b43_nphy_get_ipa_gain_table(dev);
+                               } else {
+                                       if (band == IEEE80211_BAND_5GHZ) {
+                                               if (dev->phy.rev == 3)
+                                                       table = b43_ntab_tx_gain_rev3_5ghz;
+                                               else if (dev->phy.rev == 4)
+                                                       table = b43_ntab_tx_gain_rev4_5ghz;
+                                               else
+                                                       table = b43_ntab_tx_gain_rev5plus_5ghz;
+                                       } else {
+                                               table = b43_ntab_tx_gain_rev3plus_2ghz;
+                                       }
+                               }
+
+                               target.ipa[i] = (table[index[i]] >> 16) & 0xF;
+                               target.pad[i] = (table[index[i]] >> 20) & 0xF;
+                               target.pga[i] = (table[index[i]] >> 24) & 0xF;
+                               target.txgm[i] = (table[index[i]] >> 28) & 0xF;
+                       } else {
+                               table = b43_ntab_tx_gain_rev0_1_2;
+
+                               target.ipa[i] = (table[index[i]] >> 16) & 0x3;
+                               target.pad[i] = (table[index[i]] >> 18) & 0x3;
+                               target.pga[i] = (table[index[i]] >> 20) & 0x7;
+                               target.txgm[i] = (table[index[i]] >> 23) & 0x7;
+                       }
+               }
+       }
+
+       return target;
+}
+
+/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreCal */
+static void b43_nphy_restore_cal(struct b43_wldev *dev)
+{
+       struct b43_phy_n *nphy = dev->phy.n;
+
+       u16 coef[4];
+       u16 *loft = NULL;
+       u16 *table = NULL;
+
+       int i;
+       u16 *txcal_radio_regs = NULL;
+       struct b43_phy_n_iq_comp *rxcal_coeffs = NULL;
+
+       if (b43_current_band(dev->wl) == IEEE80211_BAND_2GHZ) {
+               if (nphy->iqcal_chanspec_2G == 0)
+                       return;
+               table = nphy->cal_cache.txcal_coeffs_2G;
+               loft = &nphy->cal_cache.txcal_coeffs_2G[5];
+       } else {
+               if (nphy->iqcal_chanspec_5G == 0)
+                       return;
+               table = nphy->cal_cache.txcal_coeffs_5G;
+               loft = &nphy->cal_cache.txcal_coeffs_5G[5];
+       }
+
+       /* TODO: Write an N PHY table with ID 15, length 4, offset 80,
+               width 16, and data from table */
+
+       for (i = 0; i < 4; i++) {
+               if (dev->phy.rev >= 3)
+                       table[i] = coef[i];
+               else
+                       coef[i] = 0;
+       }
+
+       /* TODO: Write an N PHY table with ID 15, length 4, offset 88,
+               width 16, and data from coef */
+       /* TODO: Write an N PHY table with ID 15, length 2, offset 85,
+               width 16 and data from loft */
+       /* TODO: Write an N PHY table with ID 15, length 2, offset 93,
+               width 16 and data from loft */
+
+       if (dev->phy.rev < 2)
+               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;
+               rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_2G;
+       } else {
+               txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_5G;
+               rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_5G;
+       }
+
+       /* TODO use some definitions */
+       if (dev->phy.rev >= 3) {
+               b43_radio_write(dev, 0x2021, txcal_radio_regs[0]);
+               b43_radio_write(dev, 0x2022, txcal_radio_regs[1]);
+               b43_radio_write(dev, 0x3021, txcal_radio_regs[2]);
+               b43_radio_write(dev, 0x3022, txcal_radio_regs[3]);
+               b43_radio_write(dev, 0x2023, txcal_radio_regs[4]);
+               b43_radio_write(dev, 0x2024, txcal_radio_regs[5]);
+               b43_radio_write(dev, 0x3023, txcal_radio_regs[6]);
+               b43_radio_write(dev, 0x3024, txcal_radio_regs[7]);
+       } else {
+               b43_radio_write(dev, 0x8B, txcal_radio_regs[0]);
+               b43_radio_write(dev, 0xBA, txcal_radio_regs[1]);
+               b43_radio_write(dev, 0x8D, txcal_radio_regs[2]);
+               b43_radio_write(dev, 0xBC, txcal_radio_regs[3]);
+       }
+       b43_nphy_rx_iq_coeffs(dev, true, rxcal_coeffs);
+}
+
 /*
  * Init N-PHY
  * http://bcm-v4.sipsolutions.net/802.11/PHY/Init/N
@@ -1034,7 +1572,7 @@ int b43_phy_initn(struct b43_wldev *dev)
                if (do_rssi_cal)
                        b43_nphy_rssi_cal(dev);
                else
-                       ;/* b43_nphy_restore_rssi_cal(dev); */
+                       b43_nphy_restore_rssi_cal(dev);
        } else {
                b43_nphy_rssi_cal(dev);
        }
@@ -1049,7 +1587,7 @@ int b43_phy_initn(struct b43_wldev *dev)
                        do_cal = false;
 
                if (do_cal) {
-                       /* target = b43_nphy_get_tx_gains(dev); */
+                       target = b43_nphy_get_tx_gains(dev);
 
                        if (nphy->antsel_type == 2)
                                ;/*TODO NPHY Superswitch Init with argument 1*/
@@ -1061,7 +1599,7 @@ int b43_phy_initn(struct b43_wldev *dev)
                                        nphy->cal_orig_pwr_idx[1] =
                                            nphy->txpwrindex[1].index_internal;
                                        /* TODO N PHY Pre Calibrate TX Gain */
-                                       /*target = b43_nphy_get_tx_gains(dev)*/
+                                       target = b43_nphy_get_tx_gains(dev);
                                }
                        }
                }
@@ -1084,7 +1622,7 @@ int b43_phy_initn(struct b43_wldev *dev)
        b43_phy_write(dev, B43_NPHY_TXMACDELAY, 0x0320);
        if (phy->rev >= 3 && phy->rev <= 6)
                b43_phy_write(dev, B43_NPHY_PLOAD_CSENSE_EXTLEN, 0x0014);
-       /* b43_nphy_tx_lp_fbw(dev); */
+       b43_nphy_tx_lp_fbw(dev);
        /* TODO N PHY Spur Workaround */
 
        b43err(dev->wl, "IEEE 802.11n devices are not supported, yet.\n");