27 #include <linux/slab.h>
28 #include <linux/types.h>
101 static void b43_nphy_force_rf_sequence(
struct b43_wldev *dev,
120 for (i = 0; i < 200; i++) {
125 b43err(dev->
wl,
"RF sequence status timeout\n");
136 u16 en_addrs[3][2] = {
137 { 0x0E7, 0x0EC }, { 0x342, 0x343 }, { 0x346, 0x347 }
147 for (i = 0; i < 2; i++) {
149 b43err(dev->
wl,
"Invalid override value %d\n",
override);
152 en_addr = en_addrs[
override][
i];
161 if (!core || (core & (1 << i))) {
171 static void b43_nphy_rf_control_override(
struct b43_wldev *dev,
u16 field,
172 u16 value,
u8 core,
bool off)
176 u8 addr, en_addr, val_addr;
180 if (dev->
phy.rev >= 3) {
182 for (i = 0; i < 2; i++) {
183 if (index == 0 || index == 16) {
185 "Unsupported RF Ctrl Override call\n");
200 if (core == 0 || ((1 << i) & core)) {
217 for (i = 0; i < 2; i++) {
218 if (index <= 1 || index == 16) {
220 "Unsupported RF Ctrl Override call\n");
224 if (index == 2 || index == 10 ||
225 (index >= 13 && index <= 15)) {
235 (value << rf_ctrl->
shift));
247 static void b43_nphy_rf_control_intc_override(
struct b43_wldev *dev,
u8 field,
256 for (i = 0; i < 2; i++) {
257 if ((core == 1 && i == 1) || (core == 2 && !i))
272 0xFC3F, (value << 6));
277 for (j = 0; j < 100; j++) {
286 "intc override timeout\n");
291 0xFC3F, (value << 6));
296 for (j = 0; j < 100; j++) {
305 "intc override timeout\n");
349 static void b43_nphy_write_clip_detection(
struct b43_wldev *dev,
357 static void b43_nphy_read_clip_detection(
struct b43_wldev *dev,
u16 *clip_st)
368 if (dev->
dev->core_rev == 16)
378 if (dev->
dev->core_rev == 16)
385 static void b43_nphy_reset_cca(
struct b43_wldev *dev)
399 static void b43_nphy_stay_in_carrier_search(
struct b43_wldev *dev,
bool enable)
405 static const u16 clip[] = { 0xFFFF, 0xFFFF };
408 b43_nphy_classifier(dev, 0x7, 0);
409 b43_nphy_read_clip_detection(dev, nphy->
clip_state);
410 b43_nphy_write_clip_detection(dev, clip);
412 b43_nphy_reset_cca(dev);
416 b43_nphy_write_clip_detection(dev, nphy->
clip_state);
422 static void b43_nphy_adjust_lna_gain_table(
struct b43_wldev *dev)
431 static const u16 lna_gain[4] = { -2, 10, 19, 25 };
434 b43_nphy_stay_in_carrier_search(dev, 1);
441 tmp = 40370 - 315 * dev->
phy.channel;
442 gain[0] = ((tmp >> 13) + ((tmp >> 12) & 1));
443 tmp = 23242 - 224 * dev->
phy.channel;
444 gain[1] = ((tmp >> 13) + ((tmp >> 12) & 1));
451 for (i = 0; i < 2; i++) {
453 data[0] = 19 + gain[
i];
454 data[1] = 25 + gain[
i];
455 data[2] = 25 + gain[
i];
456 data[3] = 25 + gain[
i];
458 data[0] = lna_gain[0] + gain[
i];
459 data[1] = lna_gain[1] + gain[
i];
460 data[2] = lna_gain[2] + gain[
i];
461 data[3] = lna_gain[3] + gain[
i];
465 minmax[
i] = 23 + gain[
i];
474 b43_nphy_stay_in_carrier_search(dev, 0);
478 static void b43_nphy_set_rf_sequence(
struct b43_wldev *dev,
u8 cmd,
483 u8 end = (dev->
phy.rev >= 3) ? 0x1F : 0x0F;
488 b43_nphy_stay_in_carrier_search(dev,
true);
493 for (i = length; i < 16; i++) {
499 b43_nphy_stay_in_carrier_search(dev,
false);
507 static u8 b43_radio_2057_rcal(
struct b43_wldev *dev)
523 b43err(dev->
wl,
"Radio 0x2057 rcal timeout\n");
562 b43dbg(dev->
wl,
"Radio 0x2057 rccal timeout\n");
575 b43dbg(dev->
wl,
"Radio 0x2057 rccal timeout\n");
589 b43err(dev->
wl,
"Radio 0x2057 rcal timeout\n");
597 static void b43_radio_2057_init_pre(
struct b43_wldev *dev)
606 static void b43_radio_2057_init_post(
struct b43_wldev *dev)
616 if (dev->
phy.n->init_por) {
617 b43_radio_2057_rcal(dev);
618 b43_radio_2057_rccal(dev);
622 dev->
phy.n->init_por =
false;
626 static void b43_radio_2057_init(
struct b43_wldev *dev)
628 b43_radio_2057_init_pre(dev);
630 b43_radio_2057_init_post(dev);
637 static void b43_chantab_radio_2056_upload(
struct b43_wldev *dev,
713 static void b43_radio_2056_setup(
struct b43_wldev *dev,
721 u16 pag_boost, padg_boost, pgag_boost, mixg_boost;
722 u16 paa_boost, pada_boost, pgaa_boost, mixa_boost;
726 b43_chantab_radio_2056_upload(dev, e);
733 if (dev->
dev->chip_id == 0x4716) {
750 for (i = 0; i < 2; i++) {
752 if (dev->
phy.rev >= 5) {
756 if (dev->
dev->chip_id == 0x4716) {
793 bias = dev->
phy.is_40mhz ? 0x40 : 0x20;
813 }
else if (freq < 5340) {
818 }
else if (freq < 5650) {
827 pgaa_boost = -(freq - 18) / 36 + 168;
833 for (i = 0; i < 2; i++) {
869 static u8 b43_radio_2056_rcal(
struct b43_wldev *dev)
887 b43err(dev->
wl,
"Radio recalibration timeout\n");
900 static void b43_radio_init2056_pre(
struct b43_wldev *dev)
913 static void b43_radio_init2056_post(
struct b43_wldev *dev)
922 if (dev->
phy.n->init_por)
923 b43_radio_2056_rcal(dev);
930 static void b43_radio_init2056(
struct b43_wldev *dev)
932 b43_radio_init2056_pre(dev);
934 b43_radio_init2056_post(dev);
936 dev->
phy.n->init_por =
false;
943 static void b43_chantab_radio_upload(
struct b43_wldev *dev,
981 static void b43_radio_2055_setup(
struct b43_wldev *dev,
986 b43_chantab_radio_upload(dev, e);
995 static void b43_radio_init2055_pre(
struct b43_wldev *dev)
1006 static void b43_radio_init2055_post(
struct b43_wldev *dev)
1010 bool workaround =
false;
1014 && dev->
dev->board_type == 0x46D
1015 && dev->
dev->board_rev >= 0x41);
1033 b43err(dev->
wl,
"radio post init timeout\n");
1056 static void b43_radio_init2055(
struct b43_wldev *dev)
1058 b43_radio_init2055_pre(dev);
1066 b43_radio_init2055_post(dev);
1074 static int b43_nphy_load_samples(
struct b43_wldev *dev,
1082 b43err(dev->
wl,
"allocation for samples loading failed\n");
1086 b43_nphy_stay_in_carrier_search(dev, 1);
1088 for (i = 0; i < len; i++) {
1089 data[
i] = (samples[
i].
i & 0x3FF << 10);
1090 data[
i] |= samples[
i].
q & 0x3FF;
1096 b43_nphy_stay_in_carrier_search(dev, 0);
1109 bw = (dev->
phy.is_40mhz) ? 40 : 20;
1118 if (dev->
phy.is_40mhz)
1126 b43err(dev->
wl,
"allocation for samples generation failed\n");
1129 rot = (((freq * 36) / bw) << 16) / 100;
1132 for (i = 0; i < len; i++) {
1139 i = b43_nphy_load_samples(dev, samples, len);
1141 return (i < 0) ? 0 : len;
1145 static void b43_nphy_run_samples(
struct b43_wldev *dev,
u16 samps,
u16 loops,
1146 u16 wait,
bool iqmode,
bool dac_test)
1154 b43_nphy_stay_in_carrier_search(dev,
true);
1161 if (!dev->
phy.is_40mhz)
1168 b43_nphy_stay_in_carrier_search(dev,
false);
1172 if (loops != 0xFFFF)
1191 for (i = 0; i < 100; i++) {
1199 b43err(dev->
wl,
"run samples timeout\n");
1209 static void b43_nphy_scale_offset_rssi(
struct b43_wldev *dev,
u16 scale,
1210 s8 offset,
u8 core,
u8 rail,
1214 bool core1or5 = (core == 1) || (core == 5);
1215 bool core2or5 = (core == 2) || (core == 5);
1218 tmp = ((scale & 0x3F) << 8) | (offset & 0x3F);
1291 for (i = 0; i < 2; i++) {
1292 if ((code == 1 && i == 1) || (code == 2 && !i))
1337 if (type != 3 && type != 6) {
1339 b43_current_band(dev->
wl);
1341 if (b43_nphy_ipa(dev))
1345 reg = (i == 0) ? 0x2000 : 0x3000;
1359 static void b43_nphy_rev2_rssi_select(
struct b43_wldev *dev,
u8 code,
u8 type)
1372 val = (val << 12) | (val << 14);
1421 static void b43_nphy_rssi_select(
struct b43_wldev *dev,
u8 code,
u8 type)
1423 if (dev->
phy.rev >= 3)
1424 b43_nphy_rev3_rssi_select(dev, code, type);
1426 b43_nphy_rev2_rssi_select(dev, code, type);
1430 static void b43_nphy_set_rssi_2055_vcm(
struct b43_wldev *dev,
u8 type,
u8 *
buf)
1433 for (i = 0; i < 2; i++) {
1444 0xFC, buf[2 * i + 1]);
1452 0xF3, buf[2 * i + 1] << 2);
1458 static int b43_nphy_poll_rssi(
struct b43_wldev *dev,
u8 type,
s32 *buf,
1463 u16 save_regs_phy[9];
1466 if (dev->
phy.rev >= 3) {
1477 save_regs_phy[8] = 0;
1486 save_regs_phy[7] = 0;
1487 save_regs_phy[8] = 0;
1490 b43_nphy_rssi_select(dev, 5, type);
1492 if (dev->
phy.rev < 2) {
1497 for (i = 0; i < 4; i++)
1500 for (i = 0; i < nsamp; i++) {
1501 if (dev->
phy.rev < 2) {
1509 buf[0] += ((
s8)((s[0] & 0x3F) << 2)) >> 2;
1510 buf[1] += ((
s8)(((s[0] >> 8) & 0x3F) << 2)) >> 2;
1511 buf[2] += ((
s8)((s[1] & 0x3F) << 2)) >> 2;
1512 buf[3] += ((
s8)(((s[1] >> 8) & 0x3F) << 2)) >> 2;
1514 out = (buf[0] & 0xFF) << 24 | (buf[1] & 0xFF) << 16 |
1515 (buf[2] & 0xFF) << 8 | (buf[3] & 0xFF);
1517 if (dev->
phy.rev < 2)
1520 if (dev->
phy.rev >= 3) {
1545 static void b43_nphy_rev3_rssi_cal(
struct b43_wldev *dev)
1549 u16 saved_regs_phy_rfctl[2];
1550 u16 saved_regs_phy[13];
1551 u16 regs_to_store[] = {
1564 u16 clip_off[2] = { 0xFFFF, 0xFFFF };
1568 s32 results[8][4] = { };
1569 s32 results_min[4] = { };
1570 s32 poll_results[4] = { };
1572 u16 *rssical_radio_regs =
NULL;
1579 class = b43_nphy_classifier(dev, 0, 0);
1580 b43_nphy_classifier(dev, 7, 4);
1581 b43_nphy_read_clip_detection(dev, clip_state);
1582 b43_nphy_write_clip_detection(dev, clip_off);
1586 for (i = 0; i <
ARRAY_SIZE(regs_to_store); i++)
1587 saved_regs_phy[i] =
b43_phy_read(dev, regs_to_store[i]);
1589 b43_nphy_rf_control_intc_override(dev, 0, 0, 7);
1590 b43_nphy_rf_control_intc_override(dev, 1, 1, 7);
1591 b43_nphy_rf_control_override(dev, 0x1, 0, 0,
false);
1592 b43_nphy_rf_control_override(dev, 0x2, 1, 0,
false);
1593 b43_nphy_rf_control_override(dev, 0x80, 1, 0,
false);
1594 b43_nphy_rf_control_override(dev, 0x40, 1, 0,
false);
1597 b43_nphy_rf_control_override(dev, 0x20, 0, 0,
false);
1598 b43_nphy_rf_control_override(dev, 0x10, 1, 0,
false);
1600 b43_nphy_rf_control_override(dev, 0x10, 0, 0,
false);
1601 b43_nphy_rf_control_override(dev, 0x20, 1, 0,
false);
1604 rx_core_state = b43_nphy_get_rx_core_state(dev);
1605 for (core = 0; core < 2; core++) {
1606 if (!(rx_core_state & (1 << core)))
1609 b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, 0, 2);
1610 b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, 1, 2);
1611 for (i = 0; i < 8; i++) {
1614 b43_nphy_poll_rssi(dev, 2, results[i], 8);
1616 for (i = 0; i < 4; i += 2) {
1623 for (j = 0; j < 8; j++) {
1624 curr = results[
j][
i] * results[
j][
i] +
1625 results[
j][i + 1] * results[
j][
i];
1630 if (results[j][i] < minpoll)
1631 minpoll = results[
j][
i];
1634 results_min[
i] = minpoll;
1638 for (i = 0; i < 4; i++) {
1641 offset[
i] = -results[vcm_final][
i];
1643 offset[
i] = -((
abs(offset[i]) + 4) / 8);
1645 offset[
i] = (offset[
i] + 4) / 8;
1646 if (results_min[i] == 248)
1648 b43_nphy_scale_offset_rssi(dev, 0, offset[i],
1649 (i / 2 == 0) ? 1 : 2,
1650 (i % 2 == 0) ? 0 : 1,
1654 for (core = 0; core < 2; core++) {
1655 if (!(rx_core_state & (1 << core)))
1657 for (i = 0; i < 2; i++) {
1658 b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, 0, i);
1659 b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, 1, i);
1660 b43_nphy_poll_rssi(dev, i, poll_results, 8);
1661 for (j = 0; j < 4; j++) {
1662 if (j / 2 == core) {
1663 offset[
j] = 232 - poll_results[
j];
1665 offset[
j] = -(
abs(offset[j] + 4) / 8);
1667 offset[
j] = (offset[
j] + 4) / 8;
1668 b43_nphy_scale_offset_rssi(dev, 0,
1669 offset[2 * core], core + 1, j % 2, i);
1688 for (i = 0; i <
ARRAY_SIZE(regs_to_store); i++)
1693 rssical_radio_regs = nphy->
rssical_cache.rssical_radio_regs_2G;
1696 rssical_radio_regs = nphy->
rssical_cache.rssical_radio_regs_5G;
1721 b43_nphy_classifier(dev, 7,
class);
1722 b43_nphy_write_clip_detection(dev, clip_state);
1726 static void b43_nphy_rev2_rssi_cal(
struct b43_wldev *dev,
u8 type)
1731 u16 class,
override;
1732 u8 regs_save_radio[2];
1733 u16 regs_save_phy[2];
1740 u16 clip_off[2] = { 0xFFFF, 0xFFFF };
1741 s32 results_min[4] = { };
1742 u8 vcm_final[4] = { };
1743 s32 results[4][4] = { };
1744 s32 miniq[4][2] = { };
1749 }
else if (type < 2) {
1757 class = b43_nphy_classifier(dev, 0, 0);
1758 b43_nphy_classifier(dev, 7, 4);
1759 b43_nphy_read_clip_detection(dev, clip_state);
1760 b43_nphy_write_clip_detection(dev, clip_off);
1784 b43_nphy_rssi_select(dev, 5, type);
1785 b43_nphy_scale_offset_rssi(dev, 0, 0, 5, 0, type);
1786 b43_nphy_scale_offset_rssi(dev, 0, 0, 5, 1, type);
1788 for (i = 0; i < 4; i++) {
1790 for (j = 0; j < 4; j++)
1793 b43_nphy_set_rssi_2055_vcm(dev, type, tmp);
1794 b43_nphy_poll_rssi(dev, type, results[i], 8);
1796 for (j = 0; j < 2; j++)
1797 miniq[i][j] =
min(results[i][2 * j],
1798 results[i][2 * j + 1]);
1801 for (i = 0; i < 4; i++) {
1806 for (j = 0; j < 4; j++) {
1808 curr =
abs(results[j][i]);
1810 curr =
abs(miniq[j][i / 2] - code * 8);
1817 if (results[j][i] < minpoll)
1818 minpoll = results[
j][
i];
1820 results_min[
i] = minpoll;
1821 vcm_final[
i] = minvcm;
1825 b43_nphy_set_rssi_2055_vcm(dev, type, vcm_final);
1827 for (i = 0; i < 4; i++) {
1828 offset[
i] = (code * 8) - results[vcm_final[i]][i];
1831 offset[
i] = -((
abs(offset[i]) + 4) / 8);
1833 offset[
i] = (offset[
i] + 4) / 8;
1835 if (results_min[i] == 248)
1836 offset[
i] = code - 32;
1838 core = (i / 2) ? 2 : 1;
1839 rail = (i % 2) ? 1 : 0;
1841 b43_nphy_scale_offset_rssi(dev, 0, offset[i], core, rail,
1850 b43_nphy_rssi_select(dev, 1, 2);
1853 b43_nphy_rssi_select(dev, 1, 0);
1856 b43_nphy_rssi_select(dev, 1, 1);
1859 b43_nphy_rssi_select(dev, 1, 1);
1865 b43_nphy_rssi_select(dev, 2, 2);
1868 b43_nphy_rssi_select(dev, 2, 0);
1871 b43_nphy_rssi_select(dev, 2, 1);
1875 b43_nphy_rssi_select(dev, 0, type);
1882 b43_nphy_classifier(dev, 7,
class);
1883 b43_nphy_write_clip_detection(dev, clip_state);
1886 b43_nphy_reset_cca(dev);
1893 static void b43_nphy_rssi_cal(
struct b43_wldev *dev)
1895 if (dev->
phy.rev >= 3) {
1896 b43_nphy_rev3_rssi_cal(dev);
1908 static void b43_nphy_gain_ctl_workarounds_rev3plus(
struct b43_wldev *dev)
1916 u8 lpf_gain[6] = { 0x00, 0x06, 0x0C, 0x12, 0x12, 0x12 };
1917 u8 lpf_bits[6] = { 0, 1, 2, 3, 3, 3 };
1925 if (ghz5 && dev->
phy.rev >= 5)
1995 static void b43_nphy_gain_ctl_workarounds_rev1_2(
struct b43_wldev *dev)
2002 u8 rfseq_events[3] = { 6, 8, 7 };
2003 u8 rfseq_delays[3] = { 10, 30, 1 };
2013 if (!dev->
phy.is_40mhz) {
2027 if (!dev->
phy.is_40mhz) {
2047 code = dev->
phy.is_40mhz ? 6 : 7;
2058 for (i = 0; i < 4; i++)
2061 b43_nphy_adjust_lna_gain_table(dev);
2078 for (i = 0; i < 4; i++)
2080 (code << 8 | 0x74));
2083 if (dev->
phy.rev == 2) {
2084 for (i = 0; i < 4; i++) {
2086 (0x0400 * i) + 0x0020);
2087 for (j = 0; j < 21; j++) {
2088 tmp = j * (i < 2 ? 3 : 1);
2095 b43_nphy_set_rf_sequence(dev, 5, rfseq_events, rfseq_delays, 3);
2105 static void b43_nphy_gain_ctl_workarounds(
struct b43_wldev *dev)
2107 if (dev->
phy.rev >= 7)
2109 else if (dev->
phy.rev >= 3)
2110 b43_nphy_gain_ctl_workarounds_rev3plus(dev);
2112 b43_nphy_gain_ctl_workarounds_rev1_2(dev);
2119 offset = (dev->
phy.is_40mhz) ? 0x159 : 0x154;
2123 static void b43_nphy_workarounds_rev7plus(
struct b43_wldev *dev)
2128 u8 rx2tx_events_ipa[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
2130 u8 rx2tx_delays_ipa[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
2132 u16 ntab7_15e_16e[] = { 0x10f, 0x10f };
2133 u8 ntab7_138_146[] = { 0x11, 0x11 };
2134 u8 ntab7_133[] = { 0x77, 0x11, 0x11 };
2136 u16 lpf_20, lpf_40, lpf_11b;
2137 u16 bcap_val, bcap_val_11b, bcap_val_11n_20, bcap_val_11n_40;
2138 u16 scap_val, scap_val_11b, scap_val_11n_20, scap_val_11n_40;
2139 bool rccal_ovrd =
false;
2141 u16 rx2tx_lut_20_11b, rx2tx_lut_20_11n, rx2tx_lut_40_11n;
2147 if (phy->
rev == 7) {
2166 if (phy->
rev <= 8) {
2181 if (b43_nphy_ipa(dev))
2182 b43_nphy_set_rf_sequence(dev, 0, rx2tx_events_ipa,
2183 rx2tx_delays_ipa,
ARRAY_SIZE(rx2tx_events_ipa));
2188 lpf_20 = b43_nphy_read_lpf_ctl(dev, 0x154);
2189 lpf_40 = b43_nphy_read_lpf_ctl(dev, 0x159);
2190 lpf_11b = b43_nphy_read_lpf_ctl(dev, 0x152);
2191 if (b43_nphy_ipa(dev)) {
2196 scap_val_11b = scap_val;
2197 bcap_val_11b = bcap_val;
2199 scap_val_11n_20 = scap_val;
2200 bcap_val_11n_20 = bcap_val;
2201 scap_val_11n_40 = bcap_val_11n_40 = 0xc;
2207 scap_val_11n_20 = 0xc;
2208 bcap_val_11n_20 = 0xc;
2209 scap_val_11n_40 = 0xa;
2210 bcap_val_11n_40 = 0xa;
2212 scap_val_11n_20 = 0x14;
2213 bcap_val_11n_20 = 0x14;
2214 scap_val_11n_40 = 0xf;
2215 bcap_val_11n_40 = 0xf;
2226 scap_val_11b = scap_val;
2227 bcap_val_11b = bcap_val;
2228 scap_val_11n_20 = 0x11;
2229 scap_val_11n_40 = 0x11;
2230 bcap_val_11n_20 = 0x13;
2231 bcap_val_11n_40 = 0x13;
2236 rx2tx_lut_20_11b = (bcap_val_11b << 8) |
2237 (scap_val_11b << 3) |
2239 rx2tx_lut_20_11n = (bcap_val_11n_20 << 8) |
2240 (scap_val_11n_20 << 3) |
2242 rx2tx_lut_40_11n = (bcap_val_11n_40 << 8) |
2243 (scap_val_11n_40 << 3) |
2245 for (core = 0; core < 2; core++) {
2263 b43_nphy_rf_control_override_rev7(dev, 16, 1, 3,
false, 2);
2267 b43_nphy_rf_control_override_rev7(dev, 4, 1, 3,
false, 0);
2286 for (core = 0; core < 2; core++) {
2300 if (b43_nphy_ipa(dev)) {
2304 for (core = 0; core < 2; core++) {
2314 for (core = 0; core < 2; core++) {
2350 if ((freq >= 5180 && freq <= 5230) ||
2351 (freq >= 5745 && freq <= 5805)) {
2358 for (core = 0; core < 2; core++) {
2373 for (core = 0; core < 2; core++) {
2421 b43_nphy_gain_ctl_workarounds(dev);
2435 static void b43_nphy_workarounds_rev3plus(
struct b43_wldev *dev)
2441 u8 tx2rx_events[8] = { 0x4, 0x3, 0x6, 0x5, 0x2, 0x1, 0x8, 0x1F };
2442 u8 tx2rx_delays[8] = { 8, 4, 2, 2, 4, 4, 6, 1 };
2444 u8 rx2tx_events_ipa[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
2446 u8 rx2tx_delays_ipa[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
2447 u8 rx2tx_events[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0x3, 0x4, 0x1F };
2448 u8 rx2tx_delays[9] = { 8, 6, 6, 4, 4, 18, 42, 1, 1 };
2471 b43_nphy_set_rf_sequence(dev, 1, tx2rx_events, tx2rx_delays,
2475 if (b43_nphy_ipa(dev))
2476 b43_nphy_set_rf_sequence(dev, 0, rx2tx_events_ipa,
2477 rx2tx_delays_ipa,
ARRAY_SIZE(rx2tx_events_ipa));
2480 if (b43_nphy_ipa(dev)) {
2481 rx2tx_delays[5] = 59;
2482 rx2tx_delays[6] = 1;
2483 rx2tx_events[7] = 0x1F;
2485 b43_nphy_set_rf_sequence(dev, 0, rx2tx_events, rx2tx_delays,
2495 if (!dev->
phy.is_40mhz) {
2503 b43_nphy_gain_ctl_workarounds(dev);
2536 if (dev->
phy.rev == 4 &&
2562 static void b43_nphy_workarounds_rev1_2(
struct b43_wldev *dev)
2568 u8 events1[7] = { 0x0, 0x1, 0x2, 0x8, 0x4, 0x5, 0x3 };
2569 u8 delays1[7] = { 0x8, 0x6, 0x6, 0x2, 0x4, 0x3C, 0x1 };
2571 u8 events2[7] = { 0x0, 0x3, 0x5, 0x4, 0x2, 0x1, 0x8 };
2572 u8 delays2[7] = { 0x8, 0x6, 0x2, 0x4, 0x4, 0x6, 0x1 };
2575 dev->
dev->board_type == 0x8B) {
2591 if (dev->
phy.rev < 3) {
2596 if (dev->
phy.rev < 2) {
2610 b43_nphy_set_rf_sequence(dev, 0, events1, delays1, 7);
2611 b43_nphy_set_rf_sequence(dev, 1, events2, delays2, 7);
2613 b43_nphy_gain_ctl_workarounds(dev);
2615 if (dev->
phy.rev < 2) {
2619 }
else if (dev->
phy.rev == 2) {
2624 if (dev->
phy.rev < 2)
2636 if (dev->
phy.rev < 3) {
2644 if (dev->
phy.rev == 2)
2650 static void b43_nphy_workarounds(
struct b43_wldev *dev)
2656 b43_nphy_classifier(dev, 1, 0);
2658 b43_nphy_classifier(dev, 1, 1);
2661 b43_nphy_stay_in_carrier_search(dev, 1);
2666 if (dev->
phy.rev >= 7)
2667 b43_nphy_workarounds_rev7plus(dev);
2668 else if (dev->
phy.rev >= 3)
2669 b43_nphy_workarounds_rev3plus(dev);
2671 b43_nphy_workarounds_rev1_2(dev);
2674 b43_nphy_stay_in_carrier_search(dev, 0);
2685 static int b43_nphy_tx_tone(
struct b43_wldev *dev,
u32 freq,
u16 max_val,
2686 bool iqmode,
bool dac_test)
2688 u16 samp = b43_nphy_gen_load_samples(dev, freq, max_val, dac_test);
2691 b43_nphy_run_samples(dev, samp, 0xFFFF, 0, iqmode, dac_test);
2696 static void b43_nphy_update_txrx_chain(
struct b43_wldev *dev)
2700 bool override =
false;
2724 static void b43_nphy_stop_playback(
struct b43_wldev *dev)
2730 b43_nphy_stay_in_carrier_search(dev, 1);
2747 b43_nphy_stay_in_carrier_search(dev, 0);
2751 static void b43_nphy_iq_cal_gain_params(
struct b43_wldev *dev,
u16 core,
2758 if (dev->
phy.rev >= 3) {
2764 (params->
pad << 4) | (params->
ipa);
2765 for (j = 0; j < 5; j++)
2766 params->
ncorr[j] = 0x79;
2768 gain = (target.
pad[
core]) | (target.
pga[core] << 4) |
2773 for (i = 0; i < 9; i++)
2783 for (j = 0; j < 4; j++)
2796 static void b43_nphy_op_adjust_txpower(
struct b43_wldev *dev)
2807 static void b43_nphy_tx_power_ctrl(
struct b43_wldev *dev,
bool enable)
2815 b43_nphy_stay_in_carrier_search(dev, 1);
2819 if (dev->
phy.rev >= 3 &&
2832 for (i = 0; i < 84; i++)
2836 for (i = 0; i < 84; i++)
2840 if (dev->
phy.rev >= 3)
2844 if (dev->
phy.rev >= 3) {
2851 if (dev->
phy.rev == 2)
2854 else if (dev->
phy.rev < 2)
2858 if (dev->
phy.rev < 2 && dev->
phy.is_40mhz)
2870 if (dev->
phy.rev >= 3) {
2880 if (dev->
phy.rev > 1)
2886 if (dev->
phy.rev >= 3) {
2893 if (dev->
phy.rev > 1)
2900 if (dev->
phy.rev >= 3) {
2907 if (dev->
phy.rev == 2)
2909 else if (dev->
phy.rev < 2)
2912 if (dev->
phy.rev < 2 && dev->
phy.is_40mhz)
2915 if (b43_nphy_ipa(dev)) {
2922 b43_nphy_stay_in_carrier_search(dev, 0);
2926 static void b43_nphy_tx_power_fix(
struct b43_wldev *dev)
2931 u8 txpi[2], bbmult,
i;
2932 u16 tmp, radio_gain, dac_gain;
2933 u16 freq = dev->
phy.channel_freq;
2938 b43_nphy_stay_in_carrier_search(dev, 1);
2940 if (dev->
phy.rev >= 7) {
2941 txpi[0] = txpi[1] = 30;
2942 }
else if (dev->
phy.rev >= 3) {
2952 }
else if (freq >= 4900 && freq < 5100) {
2955 }
else if (freq >= 5100 && freq < 5500) {
2958 }
else if (freq >= 5500) {
2966 if (dev->
phy.rev < 7 &&
2967 (txpi[0] < 40 || txpi[0] > 100 || txpi[1] < 40 || txpi[1] > 100))
2968 txpi[0] = txpi[1] = 91;
2977 for (i = 0; i < 2; i++) {
2980 if (dev->
phy.rev >= 3)
2981 radio_gain = (txgain >> 16) & 0x1FFFF;
2983 radio_gain = (txgain >> 16) & 0x1FFF;
2985 if (dev->
phy.rev >= 7)
2986 dac_gain = (txgain >> 8) & 0x7;
2988 dac_gain = (txgain >> 8) & 0x3F;
2989 bbmult = txgain & 0xFF;
2991 if (dev->
phy.rev >= 3) {
3009 tmp = (tmp & 0x00FF) | (bbmult << 8);
3011 tmp = (tmp & 0xFF00) | bbmult;
3014 if (b43_nphy_ipa(dev)) {
3016 u16 reg = (i == 0) ?
3028 b43_nphy_stay_in_carrier_search(dev, 0);
3031 static void b43_nphy_ipa_internal_tssi_setup(
struct b43_wldev *dev)
3038 if (phy->
rev >= 7) {
3039 for (core = 0; core < 2; core++) {
3040 r = core ? 0x190 : 0x170;
3072 for (core = 0; core < 2; core++) {
3113 static void b43_nphy_tx_power_ctl_idle_tssi(
struct b43_wldev *dev)
3123 if (b43_nphy_ipa(dev))
3124 b43_nphy_ipa_internal_tssi_setup(dev);
3127 b43_nphy_rf_control_override_rev7(dev, 0x2000, 0, 3,
false, 0);
3128 else if (phy->
rev >= 3)
3129 b43_nphy_rf_control_override(dev, 0x2000, 0, 3,
false);
3131 b43_nphy_stop_playback(dev);
3132 b43_nphy_tx_tone(dev, 0xFA0, 0,
false,
false);
3134 tmp = b43_nphy_poll_rssi(dev, 4, rssi, 1);
3135 b43_nphy_stop_playback(dev);
3136 b43_nphy_rssi_select(dev, 0, 0);
3139 b43_nphy_rf_control_override_rev7(dev, 0x2000, 0, 3,
true, 0);
3140 else if (phy->
rev >= 3)
3141 b43_nphy_rf_control_override(dev, 0x2000, 0, 3,
true);
3143 if (phy->
rev >= 3) {
3144 nphy->
pwr_ctl_info[0].idle_tssi_5g = (tmp >> 24) & 0xFF;
3145 nphy->
pwr_ctl_info[1].idle_tssi_5g = (tmp >> 8) & 0xFF;
3147 nphy->
pwr_ctl_info[0].idle_tssi_5g = (tmp >> 16) & 0xFF;
3150 nphy->
pwr_ctl_info[0].idle_tssi_2g = (tmp >> 24) & 0xFF;
3151 nphy->
pwr_ctl_info[1].idle_tssi_2g = (tmp >> 8) & 0xFF;
3155 static void b43_nphy_tx_prepare_adjusted_power_table(
struct b43_wldev *dev)
3162 for (i = 0; i < 4; i++)
3165 for (stf_mode = 0; stf_mode < 4; stf_mode++) {
3169 if (dev->
phy.is_40mhz && dev->
phy.rev >= 5) {
3173 idx = dev->
phy.is_40mhz ? 52 : 4;
3177 idx = dev->
phy.is_40mhz ? 76 : 28;
3180 idx = dev->
phy.is_40mhz ? 84 : 36;
3183 idx = dev->
phy.is_40mhz ? 92 : 44;
3187 for (i = 0; i < 20; i++) {
3194 if (i == 3 || i == 4 || i == 7 || i == 8 || i == 11 ||
3202 static void b43_nphy_tx_power_ctl_setup(
struct b43_wldev *dev)
3207 s16 a1[2], b0[2], b1[2];
3213 u16 freq = dev->
phy.channel_freq;
3218 if (dev->
dev->core_rev == 11 || dev->
dev->core_rev == 12) {
3225 b43_nphy_stay_in_carrier_search(dev,
true);
3228 if (dev->
phy.rev >= 3)
3235 if (dev->
dev->core_rev == 11 || dev->
dev->core_rev == 12)
3241 target[0] = target[1] = 52;
3242 a1[0] = a1[1] = -424;
3243 b0[0] = b0[1] = 5612;
3244 b1[0] = b1[1] = -1393;
3247 for (c = 0; c < 2; c++) {
3254 }
else if (freq >= 4900 && freq < 5100) {
3255 for (c = 0; c < 2; c++) {
3262 }
else if (freq >= 5100 && freq < 5500) {
3263 for (c = 0; c < 2; c++) {
3270 }
else if (freq >= 5500) {
3271 for (c = 0; c < 2; c++) {
3281 target[0] = target[1] = 52;
3282 a1[0] = a1[1] = -424;
3283 b0[0] = b0[1] = 5612;
3284 b1[0] = b1[1] = -1393;
3289 if (dev->
phy.rev >= 3) {
3290 if (sprom->
fem.ghz2.tssipos)
3292 if (dev->
phy.rev >= 7) {
3293 for (c = 0; c < 2; c++) {
3294 r = c ? 0x190 : 0x170;
3295 if (b43_nphy_ipa(dev))
3299 if (b43_nphy_ipa(dev)) {
3314 if (dev->
dev->core_rev == 11 || dev->
dev->core_rev == 12) {
3320 if (dev->
phy.rev >= 7) {
3328 if (dev->
phy.rev > 1)
3333 if (dev->
dev->core_rev == 11 || dev->
dev->core_rev == 12)
3347 for (c = 0; c < 2; c++) {
3348 for (i = 0; i < 64; i++) {
3349 num = 8 * (16 * b0[
c] + b1[
c] *
i);
3350 den = 32768 + a1[
c] *
i;
3351 pwr =
max((4 * num + den / 2) / den, -8);
3352 if (dev->
phy.rev < 3 && (i <= (31 - idle[c] + 1)))
3353 pwr =
max(pwr, target[c] + 1);
3359 b43_nphy_tx_prepare_adjusted_power_table(dev);
3366 b43_nphy_stay_in_carrier_search(dev,
false);
3369 static void b43_nphy_tx_gain_table_upload(
struct b43_wldev *dev)
3382 if (phy->
rev >= 3) {
3384 nphy->gmval = (table[0] >> 16) & 0x7000;
3387 for (i = 0; i < 128; i++) {
3388 pga_gain = (table[
i] >> 24) & 0xF;
3404 static void b43_nphy_pa_override(
struct b43_wldev *dev,
bool enable)
3415 band = b43_current_band(dev->
wl);
3416 if (dev->
phy.rev >= 3) {
3438 static void b43_nphy_tx_lp_fbw(
struct b43_wldev *dev)
3442 if (dev->
phy.rev >= 3) {
3443 if (b43_nphy_ipa(dev)) {
3446 (((((tmp << 3) | tmp) << 3) | tmp) << 3) | tmp);
3451 (((((tmp << 3) | tmp) << 3) | tmp) << 3) | tmp);
3471 for (i = 1000;
i; i--) {
3491 memset(est, 0,
sizeof(*est));
3495 static void b43_nphy_rx_iq_coeffs(
struct b43_wldev *dev,
bool write,
3514 static void b43_nphy_rx_cal_phy_cleanup(
struct b43_wldev *dev,
u8 core)
3516 u16 *
regs = dev->
phy.n->tx_rx_cal_phy_saveregs;
3537 static void b43_nphy_rx_cal_phy_setup(
struct b43_wldev *dev,
u8 core)
3540 u16 *regs = dev->
phy.n->tx_rx_cal_phy_saveregs;
3580 b43_nphy_rf_control_intc_override(dev, 2, 0, 3);
3581 b43_nphy_rf_control_override(dev, 8, 0, 3,
false);
3591 b43_nphy_rf_control_intc_override(dev, 1, rxval, (core + 1));
3592 b43_nphy_rf_control_intc_override(dev, 1, txval, (2 - core));
3597 static void b43_nphy_calc_rx_iq_comp(
struct b43_wldev *dev,
u8 mask)
3603 int iq_nbits, qq_nbits;
3615 b43_nphy_rx_iq_coeffs(dev,
false, &old);
3616 b43_nphy_rx_iq_coeffs(dev,
true, &
new);
3617 b43_nphy_rx_iq_est(dev, &est, 0x4000, 32,
false);
3620 for (i = 0; i < 2; i++) {
3621 if (i == 0 && (mask & 1)) {
3625 }
else if (i == 1 && (mask & 2)) {
3638 iq_nbits = fls(
abs(iq));
3641 arsh = iq_nbits - 20;
3643 a = -((iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
3646 a = -((iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
3655 brsh = qq_nbits - 11;
3657 b = (qq << (31 - qq_nbits));
3660 b = (qq << (31 - qq_nbits));
3667 b =
int_sqrt(b / tmp - a * a) - (1 << 10);
3669 if (i == 0 && (mask & 0x1)) {
3670 if (dev->
phy.rev >= 3) {
3677 }
else if (i == 1 && (mask & 0x2)) {
3678 if (dev->
phy.rev >= 3) {
3691 b43_nphy_rx_iq_coeffs(dev,
true, &
new);
3695 static void b43_nphy_tx_iq_workaround(
struct b43_wldev *dev)
3707 static void b43_nphy_spur_workaround(
struct b43_wldev *dev)
3712 int tone[2] = { 57, 58 };
3713 u32 noise[2] = { 0x3FF, 0x3FF };
3718 b43_nphy_stay_in_carrier_search(dev, 1);
3722 if (channel == 11 && dev->
phy.is_40mhz)
3730 if (channel == 54) {
3733 }
else if (channel == 38 || channel == 102 || channel == 118) {
3741 }
else if (channel == 134) {
3744 }
else if (channel == 151) {
3747 }
else if (channel == 153 || channel == 161) {
3755 if (!tone[0] && !noise[0])
3762 b43_nphy_stay_in_carrier_search(dev, 0);
3766 static void b43_nphy_tx_pwr_ctrl_coef_setup(
struct b43_wldev *dev)
3771 u32 cur_real, cur_imag, real_part, imag_part;
3776 b43_nphy_stay_in_carrier_search(dev,
true);
3780 for (i = 0; i < 2; i++) {
3781 tmp = ((buffer[i * 2] & 0x3FF) << 10) |
3782 (buffer[i * 2 + 1] & 0x3FF);
3784 (((i + 26) << 10) | 320));
3785 for (j = 0; j < 128; j++) {
3787 ((tmp >> 16) & 0xFFFF));
3793 for (i = 0; i < 2; i++) {
3794 tmp = buffer[5 +
i];
3795 real_part = (tmp >> 8) & 0xFF;
3796 imag_part = (tmp & 0xFF);
3798 (((i + 26) << 10) | 448));
3800 if (dev->
phy.rev >= 3) {
3801 cur_real = real_part;
3802 cur_imag = imag_part;
3803 tmp = ((cur_real & 0xFF) << 8) | (cur_imag & 0xFF);
3806 for (j = 0; j < 128; j++) {
3807 if (dev->
phy.rev < 3) {
3808 cur_real = (real_part *
loscale[
j] + 128) >> 8;
3809 cur_imag = (imag_part *
loscale[
j] + 128) >> 8;
3810 tmp = ((cur_real & 0xFF) << 8) |
3814 ((tmp >> 16) & 0xFFFF));
3820 if (dev->
phy.rev >= 3) {
3828 b43_nphy_stay_in_carrier_search(dev,
false);
3835 static void b43_nphy_restore_rssi_cal(
struct b43_wldev *dev)
3839 u16 *rssical_radio_regs =
NULL;
3845 rssical_radio_regs = nphy->
rssical_cache.rssical_radio_regs_2G;
3850 rssical_radio_regs = nphy->
rssical_cache.rssical_radio_regs_5G;
3875 static void b43_nphy_tx_cal_radio_setup(
struct b43_wldev *dev)
3882 if (dev->
phy.rev >= 3) {
3883 for (i = 0; i < 2; i++) {
3884 tmp = (i == 0) ? 0x2000 : 0x3000;
3923 (dev->
phy.rev < 5) ? 0x11 : 0x01);
3958 if (dev->
phy.rev < 2) {
3969 static void b43_nphy_update_tx_cal_ladder(
struct b43_wldev *dev,
u16 core)
3980 for (i = 0; i < 18; i++) {
3982 entry = ((scale & 0xFF) << 8) |
ladder_lo[
i].g_env;
3986 entry = ((scale & 0xFF) << 8) |
ladder_iq[
i].g_env;
3992 static void b43_nphy_ext_pa_set_tx_dig_filters(
struct b43_wldev *dev)
3995 for (i = 0; i < 15; i++)
4001 static void b43_nphy_int_pa_set_tx_dig_filters(
struct b43_wldev *dev)
4005 static const u16 offset[] = { 0x186, 0x195, 0x2C5 };
4007 for (i = 0; i < 3; i++)
4008 for (j = 0; j < 15; j++)
4012 if (dev->
phy.is_40mhz) {
4013 for (j = 0; j < 15; j++)
4017 for (j = 0; j < 15; j++)
4022 if (dev->
phy.channel == 14)
4023 for (j = 0; j < 15; j++)
4041 b43_nphy_stay_in_carrier_search(dev,
true);
4044 b43_nphy_stay_in_carrier_search(dev,
false);
4046 for (i = 0; i < 2; ++
i) {
4047 if (dev->
phy.rev >= 3) {
4048 target.ipa[
i] = curr_gain[
i] & 0x000F;
4049 target.pad[
i] = (curr_gain[
i] & 0x00F0) >> 4;
4050 target.pga[
i] = (curr_gain[
i] & 0x0F00) >> 8;
4051 target.txgm[
i] = (curr_gain[
i] & 0x7000) >> 12;
4053 target.ipa[
i] = curr_gain[
i] & 0x0003;
4054 target.pad[
i] = (curr_gain[
i] & 0x000C) >> 2;
4055 target.pga[
i] = (curr_gain[
i] & 0x0070) >> 4;
4056 target.txgm[
i] = (curr_gain[
i] & 0x0380) >> 7;
4069 for (i = 0; i < 2; ++
i) {
4071 if (dev->
phy.rev >= 3) {
4072 target.ipa[
i] = (table[index[
i]] >> 16) & 0xF;
4073 target.pad[
i] = (table[index[
i]] >> 20) & 0xF;
4074 target.pga[
i] = (table[index[
i]] >> 24) & 0xF;
4075 target.txgm[
i] = (table[index[
i]] >> 28) & 0xF;
4077 target.ipa[
i] = (table[index[
i]] >> 16) & 0x3;
4078 target.pad[
i] = (table[index[
i]] >> 18) & 0x3;
4079 target.pga[
i] = (table[index[
i]] >> 20) & 0x7;
4080 target.txgm[
i] = (table[index[
i]] >> 23) & 0x7;
4089 static void b43_nphy_tx_cal_phy_cleanup(
struct b43_wldev *dev)
4091 u16 *regs = dev->
phy.n->tx_rx_cal_phy_saveregs;
4093 if (dev->
phy.rev >= 3) {
4105 b43_nphy_reset_cca(dev);
4118 static void b43_nphy_tx_cal_phy_setup(
struct b43_wldev *dev)
4120 u16 *regs = dev->
phy.n->tx_rx_cal_phy_saveregs;
4125 if (dev->
phy.rev >= 3) {
4151 b43_nphy_rf_control_intc_override(dev, 2, 1, 3);
4152 b43_nphy_rf_control_intc_override(dev, 1, 2, 1);
4153 b43_nphy_rf_control_intc_override(dev, 1, 8, 2);
4185 static void b43_nphy_save_cal(
struct b43_wldev *dev)
4195 b43_nphy_stay_in_carrier_search(dev, 1);
4198 rxcal_coeffs = &nphy->
cal_cache.rxcal_coeffs_2G;
4199 txcal_radio_regs = nphy->
cal_cache.txcal_radio_regs_2G;
4201 table = nphy->
cal_cache.txcal_coeffs_2G;
4203 rxcal_coeffs = &nphy->
cal_cache.rxcal_coeffs_5G;
4204 txcal_radio_regs = nphy->
cal_cache.txcal_radio_regs_5G;
4206 table = nphy->
cal_cache.txcal_coeffs_5G;
4209 b43_nphy_rx_iq_coeffs(dev,
false, rxcal_coeffs);
4211 if (dev->
phy.rev >= 3) {
4231 b43_nphy_stay_in_carrier_search(dev, 0);
4235 static void b43_nphy_restore_cal(
struct b43_wldev *dev)
4250 table = nphy->
cal_cache.txcal_coeffs_2G;
4251 loft = &nphy->
cal_cache.txcal_coeffs_2G[5];
4255 table = nphy->
cal_cache.txcal_coeffs_5G;
4256 loft = &nphy->
cal_cache.txcal_coeffs_5G[5];
4261 for (i = 0; i < 4; i++) {
4262 if (dev->
phy.rev >= 3)
4272 if (dev->
phy.rev < 2)
4273 b43_nphy_tx_iq_workaround(dev);
4276 txcal_radio_regs = nphy->
cal_cache.txcal_radio_regs_2G;
4277 rxcal_coeffs = &nphy->
cal_cache.rxcal_coeffs_2G;
4279 txcal_radio_regs = nphy->
cal_cache.txcal_radio_regs_5G;
4280 rxcal_coeffs = &nphy->
cal_cache.rxcal_coeffs_5G;
4284 if (dev->
phy.rev >= 3) {
4299 b43_nphy_rx_iq_coeffs(dev,
true, rxcal_coeffs);
4303 static int b43_nphy_cal_tx_iq_lo(
struct b43_wldev *dev,
4305 bool full,
bool mphase)
4322 bool updated[2] = { };
4324 b43_nphy_stay_in_carrier_search(dev,
true);
4326 if (dev->
phy.rev >= 4) {
4333 for (i = 0; i < 2; i++) {
4334 b43_nphy_iq_cal_gain_params(dev, i, target, ¶ms[i]);
4340 b43_nphy_tx_cal_radio_setup(dev);
4341 b43_nphy_tx_cal_phy_setup(dev);
4343 phy6or5x = dev->
phy.rev >= 6 ||
4347 if (dev->
phy.is_40mhz) {
4362 if (!dev->
phy.is_40mhz)
4368 b43_nphy_run_samples(dev, (dev->
phy.is_40mhz ? 40 : 20) * 8,
4369 0xFFFF, 0,
true,
false);
4371 error = b43_nphy_tx_tone(dev, freq, 250,
true,
false);
4377 if (dev->
phy.rev < 3)
4383 if (dev->
phy.rev < 3)
4387 if (dev->
phy.rev >= 3) {
4400 if (dev->
phy.rev >= 3)
4405 if (dev->
phy.rev >= 3)
4420 for (; count < numb; count++) {
4422 if (dev->
phy.rev >= 3)
4427 if (dev->
phy.rev >= 3)
4433 core = (cmd & 0x3000) >> 12;
4434 type = (cmd & 0x0F00) >> 8;
4436 if (phy6or5x && updated[core] == 0) {
4437 b43_nphy_update_tx_cal_ladder(dev, core);
4438 updated[
core] =
true;
4444 if (type == 1 || type == 3 || type == 4) {
4447 diq_start = buffer[0];
4454 for (i = 0; i < 2000; i++) {
4466 if (type == 1 || type == 3 || type == 4)
4467 buffer[0] = diq_start;
4473 last = (dev->
phy.rev < 3) ? 6 : 7;
4478 if (dev->
phy.rev < 3) {
4493 if (dev->
phy.rev < 3)
4499 dev->
phy.channel_freq;
4501 dev->
phy.channel_type;
4504 if (dev->
phy.rev < 3)
4510 b43_nphy_stop_playback(dev);
4514 b43_nphy_tx_cal_phy_cleanup(dev);
4518 b43_nphy_tx_iq_workaround(dev);
4520 if (dev->
phy.rev >= 4)
4523 b43_nphy_stay_in_carrier_search(dev,
false);
4529 static void b43_nphy_reapply_tx_cal_coeffs(
struct b43_wldev *dev)
4542 for (i = 0; i < 4; i++) {
4552 for (i = 0; i < 4; i++)
4564 static int b43_nphy_rev2_cal_rx_iq(
struct b43_wldev *dev,
4578 u16 lna[3] = { 3, 3, 1 };
4579 u16 hpf1[3] = { 7, 2, 0 };
4580 u16 hpf2[3] = { 2, 0, 0 };
4587 bool playtone =
true;
4590 b43_nphy_stay_in_carrier_search(dev, 1);
4592 if (dev->
phy.rev < 2)
4593 b43_nphy_reapply_tx_cal_coeffs(dev);
4595 for (i = 0; i < 2; i++) {
4596 b43_nphy_iq_cal_gain_params(dev, i, target, &cal_params[i]);
4597 cal_gain[
i] = cal_params[
i].cal_gain;
4601 for (i = 0; i < 2; i++) {
4626 band = b43_current_band(dev->
wl);
4652 for (j = 0; j < 4; j++) {
4658 if (power[1] > 10000) {
4663 if (power[0] > 10000) {
4673 cur_lna = lna[
index];
4674 cur_hpf1 = hpf1[
index];
4675 cur_hpf2 = hpf2[
index];
4676 cur_hpf += desired -
hweight32(power[index]);
4684 tmp[0] = ((cur_hpf2 << 8) | (cur_hpf1 << 4) |
4686 b43_nphy_rf_control_override(dev, 0x400, tmp[0], 3,
4689 b43_nphy_stop_playback(dev);
4692 ret = b43_nphy_tx_tone(dev, 4000,
4697 b43_nphy_run_samples(dev, 160, 0xFFFF, 0,
4703 b43_nphy_rx_iq_est(dev, &est, 1024, 32,
4712 power[
i] = ((real + imag) / 1024) + 1;
4714 b43_nphy_calc_rx_iq_comp(dev, 1 << i);
4716 b43_nphy_stop_playback(dev);
4735 b43_nphy_rf_control_override(dev, 0x400, 0, 3,
true);
4739 b43_nphy_stay_in_carrier_search(dev, 0);
4744 static int b43_nphy_rev3_cal_rx_iq(
struct b43_wldev *dev,
4751 static int b43_nphy_cal_rx_iq(
struct b43_wldev *dev,
4754 if (dev->
phy.rev >= 3)
4755 return b43_nphy_rev3_cal_rx_iq(dev, target, type, debug);
4757 return b43_nphy_rev2_cal_rx_iq(dev, target, type, debug);
4761 static void b43_nphy_set_rx_core_state(
struct b43_wldev *dev,
u8 mask)
4775 b43_nphy_stay_in_carrier_search(dev,
true);
4780 if ((mask & 0x3) != 0x3) {
4782 if (dev->
phy.rev >= 3) {
4787 if (dev->
phy.rev >= 3) {
4795 b43_nphy_stay_in_carrier_search(dev,
false);
4808 static void b43_nphy_tables_init(
struct b43_wldev *dev)
4810 if (dev->
phy.rev < 3)
4817 static void b43_nphy_update_mimo_config(
struct b43_wldev *dev,
s32 preamble)
4831 static void b43_nphy_bphy_init(
struct b43_wldev *dev)
4837 for (i = 0; i < 16; i++) {
4842 for (i = 0; i < 16; i++) {
4850 static void b43_nphy_superswitch_init(
struct b43_wldev *dev,
bool init)
4852 if (dev->
phy.rev >= 3) {
4865 switch (dev->
dev->bus_type) {
4866 #ifdef CONFIG_B43_BCMA
4872 #ifdef CONFIG_B43_SSB
4907 bool do_cal =
false;
4909 if ((dev->
phy.rev >= 3) &&
4912 switch (dev->
dev->bus_type) {
4913 #ifdef CONFIG_B43_BCMA
4919 #ifdef CONFIG_B43_SSB
4928 b43_nphy_tables_init(dev);
4933 if (dev->
phy.rev >= 3) {
4943 if (dev->
phy.rev < 6) {
4950 if (dev->
phy.rev >= 3)
4954 if (dev->
phy.rev <= 2) {
4955 tmp = (dev->
phy.rev == 2) ? 0x3B : 0x40;
4965 dev->
dev->board_type == 0x8B))
4974 b43_nphy_update_txrx_chain(dev);
4981 tmp2 = b43_current_band(dev->
wl);
4982 if (b43_nphy_ipa(dev)) {
4989 b43_nphy_int_pa_set_tx_dig_filters(dev);
4990 }
else if (phy->
rev >= 5) {
4991 b43_nphy_ext_pa_set_tx_dig_filters(dev);
4994 b43_nphy_workarounds(dev);
5005 b43_nphy_pa_override(dev,
false);
5008 b43_nphy_pa_override(dev,
true);
5010 b43_nphy_classifier(dev, 0, 0);
5011 b43_nphy_read_clip_detection(dev, clip);
5013 b43_nphy_bphy_init(dev);
5016 b43_nphy_tx_power_ctrl(dev,
false);
5017 b43_nphy_tx_power_fix(dev);
5018 b43_nphy_tx_power_ctl_idle_tssi(dev);
5019 b43_nphy_tx_power_ctl_setup(dev);
5020 b43_nphy_tx_gain_table_upload(dev);
5023 b43_nphy_set_rx_core_state(dev, nphy->
phyrxchain);
5027 do_rssi_cal =
false;
5028 if (phy->
rev >= 3) {
5035 b43_nphy_rssi_cal(dev);
5037 b43_nphy_restore_rssi_cal(dev);
5039 b43_nphy_rssi_cal(dev);
5052 target = b43_nphy_get_tx_gains(dev);
5055 b43_nphy_superswitch_init(dev,
true);
5057 b43_nphy_rssi_cal(dev);
5058 if (phy->
rev >= 3) {
5064 target = b43_nphy_get_tx_gains(dev);
5066 if (!b43_nphy_cal_tx_iq_lo(dev, target,
true,
false))
5067 if (b43_nphy_cal_rx_iq(dev, target, 2, 0) == 0)
5068 b43_nphy_save_cal(dev);
5072 b43_nphy_restore_cal(dev);
5076 b43_nphy_tx_pwr_ctrl_coef_setup(dev);
5077 b43_nphy_tx_power_ctrl(dev, tx_pwr_state);
5080 if (phy->
rev >= 3 && phy->
rev <= 6)
5082 b43_nphy_tx_lp_fbw(dev);
5084 b43_nphy_spur_workaround(dev);
5093 static void b43_chantab_phy_upload(
struct b43_wldev *dev,
5105 static void b43_nphy_pmu_spur_avoid(
struct b43_wldev *dev,
bool avoid)
5110 switch (dev->
dev->bus_type) {
5111 #ifdef CONFIG_B43_BCMA
5113 cc = &dev->
dev->bdev->bus->drv_cc;
5114 if (dev->
dev->chip_id == 43224 || dev->
dev->chip_id == 43225) {
5131 }
else if (dev->
dev->chip_id == 0x4716) {
5149 }
else if (dev->
dev->chip_id == 0x4322 ||
5150 dev->
dev->chip_id == 0x4340 ||
5151 dev->
dev->chip_id == 0x4341) {
5166 #ifdef CONFIG_B43_SSB
5175 static void b43_nphy_channel_setup(
struct b43_wldev *dev,
5202 b43_chantab_phy_upload(dev, e);
5205 b43_nphy_classifier(dev, 2, 0);
5208 b43_nphy_classifier(dev, 2, 2);
5214 b43_nphy_tx_power_fix(dev);
5216 if (dev->
phy.rev < 3)
5217 b43_nphy_adjust_lna_gain_table(dev);
5219 b43_nphy_tx_lp_fbw(dev);
5221 if (dev->
phy.rev >= 3 &&
5227 if ((ch >= 5 && ch <= 8) || ch == 13 || ch == 14)
5231 (ch == 38 || ch == 102 || ch == 118))
5232 avoid = dev->
dev->chip_id == 0x4716;
5235 b43_nphy_pmu_spur_avoid(dev, avoid);
5237 if (dev->
dev->chip_id == 43222 || dev->
dev->chip_id == 43224 ||
5238 dev->
dev->chip_id == 43225) {
5240 avoid ? 0x5341 : 0x8889);
5244 if (dev->
phy.rev == 3 || dev->
phy.rev == 4)
5253 b43_nphy_reset_cca(dev);
5261 b43_nphy_spur_workaround(dev);
5265 static int b43_nphy_set_channel(
struct b43_wldev *dev,
5276 if (dev->
phy.rev >= 3) {
5304 if (dev->
phy.rev >= 3) {
5307 b43_radio_2056_setup(dev, tabent_r3);
5308 b43_nphy_channel_setup(dev, &(tabent_r3->
phy_regs), channel);
5312 b43_radio_2055_setup(dev, tabent_r2);
5313 b43_nphy_channel_setup(dev, &(tabent_r2->
phy_regs), channel);
5323 static int b43_nphy_op_allocate(
struct b43_wldev *dev)
5335 static void b43_nphy_op_prepare_structs(
struct b43_wldev *dev)
5341 memset(nphy, 0,
sizeof(*nphy));
5359 if (dev->
phy.rev >= 3 ||
5361 (dev->
dev->core_rev == 11 || dev->
dev->core_rev == 12))) {
5365 if (dev->
phy.rev >= 2 &&
5368 #ifdef CONFIG_B43_SSB
5372 dev->
dev->sdev->bus->host_pci;
5373 if (pdev->
device == 0x4328 ||
5383 if (dev->
phy.rev >= 3) {
5391 static void b43_nphy_op_free(
struct b43_wldev *dev)
5400 static int b43_nphy_op_init(
struct b43_wldev *dev)
5405 static inline void check_phyreg(
struct b43_wldev *dev,
u16 offset)
5410 b43err(dev->
wl,
"Invalid OFDM PHY access at "
5411 "0x%04X on N-PHY\n", offset);
5416 b43err(dev->
wl,
"Invalid EXT-G PHY access at "
5417 "0x%04X on N-PHY\n", offset);
5425 check_phyreg(dev, reg);
5430 static void b43_nphy_op_write(
struct b43_wldev *dev,
u16 reg,
u16 value)
5432 check_phyreg(dev, reg);
5437 static void b43_nphy_op_maskset(
struct b43_wldev *dev,
u16 reg,
u16 mask,
5440 check_phyreg(dev, reg);
5456 static void b43_nphy_op_radio_write(
struct b43_wldev *dev,
u16 reg,
u16 value)
5466 static void b43_nphy_op_software_rfkill(
struct b43_wldev *dev,
5470 b43err(dev->
wl,
"MAC not suspended\n");
5475 if (dev->
phy.rev >= 7) {
5477 }
else if (dev->
phy.rev >= 3) {
5495 if (dev->
phy.rev >= 7) {
5496 b43_radio_2057_init(dev);
5498 }
else if (dev->
phy.rev >= 3) {
5499 b43_radio_init2056(dev);
5502 b43_radio_init2055(dev);
5508 static void b43_nphy_op_switch_analog(
struct b43_wldev *dev,
bool on)
5510 u16 override = on ? 0x0 : 0x7FFF;
5511 u16 core = on ? 0xD : 0x00FD;
5513 if (dev->
phy.rev >= 3) {
5530 static int b43_nphy_op_switch_channel(
struct b43_wldev *dev,
5531 unsigned int new_channel)
5537 if ((new_channel < 1) || (new_channel > 14))
5540 if (new_channel > 200)
5544 return b43_nphy_set_channel(dev, channel, channel_type);
5547 static unsigned int b43_nphy_op_get_default_chan(
struct b43_wldev *dev)
5555 .allocate = b43_nphy_op_allocate,
5556 .free = b43_nphy_op_free,
5557 .prepare_structs = b43_nphy_op_prepare_structs,
5558 .init = b43_nphy_op_init,
5559 .phy_read = b43_nphy_op_read,
5560 .phy_write = b43_nphy_op_write,
5561 .phy_maskset = b43_nphy_op_maskset,
5562 .radio_read = b43_nphy_op_radio_read,
5563 .radio_write = b43_nphy_op_radio_write,
5564 .software_rfkill = b43_nphy_op_software_rfkill,
5565 .switch_analog = b43_nphy_op_switch_analog,
5566 .switch_channel = b43_nphy_op_switch_channel,
5567 .get_default_chan = b43_nphy_op_get_default_chan,
5568 .recalc_txpower = b43_nphy_op_recalc_txpower,
5569 .adjust_txpower = b43_nphy_op_adjust_txpower,