42 static const u16 rcc_table[16] = {
43 0x0002, 0x0003, 0x0001, 0x000F,
44 0x0006, 0x0007, 0x0005, 0x000F,
45 0x000A, 0x000B, 0x0009, 0x000F,
46 0x000E, 0x000F, 0x000D, 0x000F,
58 flipped |= (value & 0x0001) << 3;
59 flipped |= (value & 0x0002) << 1;
60 flipped |= (value & 0x0004) >> 1;
61 flipped |= (value & 0x0008) >> 3;
73 static const u16 frequencies_bg[14] = {
87 return frequencies_bg[channel - 1];
109 status &= ~B43legacy_MACCTL_RADIOLOCK;
123 else if (offset < 0x80)
164 for (i = 0; i < 4; i++)
167 for (i = start; i <
end; i++)
171 tmp = ((
u16)third << 14) | ((
u16)third << 6);
200 for (i = 0; i < 4; i++) {
202 tmp |= (i & 0x0001) << 1;
203 tmp |= (i & 0x0002) >> 1;
208 for (i = start; i <
end; i++)
237 channel2freq_bg(channel + 4));
240 channel2freq_bg(channel));
243 channel2freq_bg(channel));
266 for (i = 0; i < 100; i++) {
284 unsigned int channel = phy->
channel;
300 b43legacy_set_all_gains(dev, 3, 8, 1);
302 start = (channel - 5 > 0) ? channel - 5 : 1;
303 end = (channel + 5 < 14) ? channel + 5 : 13;
305 for (i = start; i <=
end; i++) {
306 if (
abs(channel - i) > 2)
318 b43legacy_set_original_gains(dev);
319 for (i = 0; i < 13; i++) {
322 end = (i + 5 < 13) ? i + 5 : 13;
323 for (j = i; j <
end; j++)
329 return ret[channel - 1];
357 for (i = 0; i < 64; i++) {
373 delta = 0x1F - phy->
nrssi[0];
374 for (i = 0; i < 64; i++) {
386 u16 backup[20] = { 0 };
449 for (i = 7; i >= 4; i--) {
456 if (v47F < 31 && saved == 0xFFFF)
496 b43legacy_set_all_gains(dev, 3, 0, 1);
505 for (i = 0; i < 4; i++) {
512 if (v47F > -31 && saved == 0xFFFF)
541 b43legacy_set_original_gains(dev);
556 u16 backup[18] = { 0 };
574 backup[11] = b43legacy_read16(dev, 0x03E2);
575 backup[12] = b43legacy_read16(dev, 0x03E6);
579 tmp &= (phy->
rev >= 5) ? 0x007F : 0x000F;
582 b43legacy_write16(dev, 0x03EC, 0x7F7F);
596 b43legacy_write16(dev, 0x03E6, 0x0040);
597 else if (phy->
analog == 0)
598 b43legacy_write16(dev, 0x03E6, 0x0122);
601 b43legacy_read16(dev,
617 b43legacy_write16(dev, 0x03E2, backup[11]);
621 b43legacy_synth_pu_workaround(dev, phy->
channel);
623 b43legacy_write16(dev, 0x03F4, backup[13]);
632 if (nrssi0 == nrssi1)
635 phy->
nrssislope = 0x00400000 / (nrssi0 - nrssi1);
638 phy->
nrssi[0] = nrssi0;
639 phy->
nrssi[1] = nrssi1;
646 b43legacy_calc_nrssi_offset(dev);
653 backup[7] = b43legacy_read16(dev, 0x03E2);
654 b43legacy_write16(dev, 0x03E2,
655 b43legacy_read16(dev, 0x03E2) | 0x8000);
663 backup[8] = b43legacy_read16(dev, 0x03E6);
678 case 4:
case 6:
case 7:
702 b43legacy_set_all_gains(dev, 0, 8, 0);
720 if (nrssi0 >= 0x0020)
732 b43legacy_read16(dev,
747 b43legacy_set_all_gains(dev, 3, 0, 1);
761 if (nrssi1 >= 0x0020)
763 if (nrssi0 == nrssi1)
766 phy->
nrssislope = 0x00400000 / (nrssi0 - nrssi1);
768 phy->
nrssi[0] = nrssi1;
769 phy->
nrssi[1] = nrssi0;
790 b43legacy_write16(dev, 0x03E2, backup[7]);
791 b43legacy_write16(dev, 0x03E6, backup[8]);
797 b43legacy_synth_pu_workaround(dev, phy->
channel);
800 b43legacy_set_original_gains(dev);
831 if (!(dev->
dev->bus->sprom.boardflags_lo &
836 threshold = (phy->
nrssi[1] - phy->
nrssi[0]) * 32;
837 threshold += 20 * (phy->
nrssi[0] + 1);
840 threshold = phy->
nrssi[1] - 5;
842 threshold =
clamp_val(threshold, 0, 0x3E);
861 !(dev->
dev->bus->sprom.boardflags_lo &
869 0x048A) & 0xF000) | 0x09EB);
873 0x048A) & 0xF000) | 0x0AED);
889 a += (phy->
nrssi[0] << 6);
898 b += (phy->
nrssi[0] << 6);
907 tmp_u16 |= ((
u32)b & 0x0000003F);
908 tmp_u16 |= (((
u32)a & 0x0000003F) << 6);
921 static void _stack_save(
u32 *_stackptr,
size_t *stackidx,
924 u32 *stackptr = &(_stackptr[*stackidx]);
929 *stackptr |= ((
u32)
id) << 13;
930 *stackptr |= ((
u32)value) << 16;
935 static u16 _stack_restore(
u32 *stackptr,
943 if ((*stackptr & 0x00001FFF) != offset)
945 if (((*stackptr & 0x00007000) >> 13) !=
id)
947 return ((*stackptr & 0xFFFF0000) >> 16);
954 #define phy_stacksave(offset) \
956 _stack_save(stack, &stackidx, 0x1, (offset), \
957 b43legacy_phy_read(dev, (offset))); \
959 #define phy_stackrestore(offset) \
961 b43legacy_phy_write(dev, (offset), \
962 _stack_restore(stack, 0x1, \
965 #define radio_stacksave(offset) \
967 _stack_save(stack, &stackidx, 0x2, (offset), \
968 b43legacy_radio_read16(dev, (offset))); \
970 #define radio_stackrestore(offset) \
972 b43legacy_radio_write16(dev, (offset), \
973 _stack_restore(stack, 0x2, \
976 #define ilt_stacksave(offset) \
978 _stack_save(stack, &stackidx, 0x3, (offset), \
979 b43legacy_ilt_read(dev, (offset))); \
981 #define ilt_stackrestore(offset) \
983 b43legacy_ilt_write(dev, (offset), \
984 _stack_restore(stack, 0x3, \
989 b43legacy_radio_interference_mitigation_enable(
struct b43legacy_wldev *dev,
1001 if (phy->
rev != 1) {
1012 flipped = flip_4bit(tmp);
1013 if (flipped < 10 && flipped >= 8)
1015 else if (flipped >= 10)
1017 flipped = flip_4bit(flipped);
1018 flipped = (flipped << 1) | 0x0020;
1093 if (phy->
rev == 2) {
1096 }
else if (phy->
rev >= 3) {
1113 & 0xFFFC) | 0x0002);
1124 & 0xFFC0) | 0x001A);
1129 else if (phy->
rev == 2) {
1139 & 0xC0FF) | 0x1800);
1142 & 0xFFC0) | 0x0015);
1145 & 0xCFFF) | 0x1000);
1148 & 0xF0FF) | 0x0A00);
1151 & 0xCFFF) | 0x1000);
1154 & 0xF0FF) | 0x0800);
1157 & 0xFFCF) | 0x0010);
1160 & 0xFFF0) | 0x0005);
1163 & 0xFFCF) | 0x0010);
1166 & 0xFFF0) | 0x0006);
1169 & 0xF0FF) | 0x0800);
1172 & 0xF0FF) | 0x0500);
1175 & 0xFFF0) | 0x000B);
1177 if (phy->
rev >= 3) {
1183 & 0x8000) | 0x36D8);
1186 & 0x8000) | 0x36D8);
1189 & 0xFE00) | 0x016D);
1196 & 0x9FFF) | 0x2000);
1199 if (!(tmp32 & 0x800)) {
1212 & 0xF0FF) | 0x0200);
1213 if (phy->
rev == 2) {
1216 & 0xFF00) | 0x007F);
1219 & 0x00FF) | 0x1300);
1220 }
else if (phy->
rev >= 6) {
1235 b43legacy_radio_interference_mitigation_disable(
struct b43legacy_wldev *dev,
1244 if (phy->
rev != 1) {
1294 if (phy->
rev >= 2) {
1302 if (phy->
rev == 2) {
1305 }
else if (phy->
rev >= 3) {
1319 if (tmp32 & 0x800) {
1332 #undef phy_stacksave
1333 #undef phy_stackrestore
1334 #undef radio_stacksave
1335 #undef radio_stackrestore
1336 #undef ilt_stacksave
1337 #undef ilt_stackrestore
1367 if (currentmode == mode)
1370 b43legacy_radio_interference_mitigation_disable(dev,
1377 b43legacy_radio_interference_mitigation_enable(dev, mode);
1390 index = (reg & 0x001E) >> 1;
1391 ret = rcc_table[
index] << 1;
1392 ret |= (reg & 0x0001);
1398 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
1405 u16 extern_lna_control;
1410 if (phy->
rev < 7 || !(dev->
dev->bus->sprom.boardflags_lo
1440 adj_loopback_gain += 0x003E;
1442 adj_loopback_gain += 0x0026;
1443 if (adj_loopback_gain >= 0x46) {
1444 adj_loopback_gain -= 0x46;
1445 extern_lna_control = 0x3000;
1446 }
else if (adj_loopback_gain >= 0x3A) {
1447 adj_loopback_gain -= 0x3A;
1448 extern_lna_control = 0x2000;
1449 }
else if (adj_loopback_gain >= 0x2E) {
1450 adj_loopback_gain -= 0x2E;
1451 extern_lna_control = 0x1000;
1453 adj_loopback_gain -= 0x10;
1454 extern_lna_control = 0x0000;
1456 for (loop = 0; loop < 16; loop++) {
1457 u16 tmp = adj_loopback_gain - 6 * loop;
1462 loop_or = (loop << 8) | extern_lna_control;
1463 if (phy->
rev >= 7 && dev->
dev->bus->sprom.boardflags_lo
1465 if (extern_lna_control)
1471 return (0x8092 | loop_or);
1473 return (0x2092 | loop_or);
1475 return (0x2093 | loop_or);
1485 return (0x0092 | loop_or);
1487 return (0x0093 | loop_or);
1499 u16 backup[21] = { 0 };
1515 backup[3] = b43legacy_read16(dev, 0x03EC);
1517 b43legacy_write16(dev, 0x03EC, 0x3F3F);
1551 b43legacy_get_812_value(dev,
1554 !(dev->
dev->bus->sprom.boardflags_lo
1567 backup[11] = b43legacy_read16(dev, 0x03E6);
1572 b43legacy_write16(dev, 0x03E6, 0x0122);
1577 & 0xFFBF) | 0x0040);
1579 (b43legacy_read16(dev,
1590 b43legacy_get_812_value(dev,
1596 b43legacy_get_812_value(dev,
1608 & 0xFFF0) | 0x0009);
1612 for (i = 0; i < 16; i++) {
1618 b43legacy_get_812_value(dev,
1624 b43legacy_get_812_value(dev,
1630 b43legacy_get_812_value(dev,
1638 b43legacy_get_812_value(dev,
1648 for (i = 0; i < 16; i++) {
1653 for (j = 0; j < 16; j++) {
1659 b43legacy_get_812_value(dev,
1665 b43legacy_get_812_value(dev,
1671 b43legacy_get_812_value(dev,
1679 b43legacy_get_812_value(dev,
1697 b43legacy_write16(dev, 0x03E6, backup[11]);
1704 b43legacy_write16(dev, 0x03EC, backup[3]);
1708 (b43legacy_read16(dev,
1734 if (frequency < 5091)
1736 else if (frequency < 5321)
1738 else if (frequency < 5806)
1748 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
1749 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
1754 for (i = 0; i < 5; i++) {
1755 for (j = 0; j < 5; j++) {
1756 if (tmp == (data_high[i] | data_low[j])) {
1767 int synthetic_pu_workaround)
1771 if (channel == 0xFF) {
1772 switch (phy->
type) {
1783 if (synthetic_pu_workaround)
1784 b43legacy_synth_pu_workaround(dev, channel);
1787 channel2freq_bg(channel));
1789 if (channel == 14) {
1790 if (dev->
dev->bus->sprom.country_code == 5)
1805 b43legacy_read16(dev,
1809 b43legacy_read16(dev,
1834 static u16 b43legacy_get_txgain_base_band(
u16 txpower)
1842 else if (txpower >= 49)
1844 else if (txpower >= 44)
1853 static u16 b43legacy_get_txgain_freq_power_amp(
u16 txpower)
1861 else if (txpower >= 25)
1863 else if (txpower >= 20)
1865 else if (txpower >= 12)
1874 static u16 b43legacy_get_txgain_dac(
u16 txpower)
1882 else if (txpower >= 49)
1884 else if (txpower >= 44)
1886 else if (txpower >= 32)
1888 else if (txpower >= 25)
1890 else if (txpower >= 20)
1892 else if (txpower >= 12)
1910 pamp = b43legacy_get_txgain_freq_power_amp(txpower);
1915 base = b43legacy_get_txgain_base_band(txpower);
1922 dac = b43legacy_get_txgain_dac(txpower);
1934 u16 baseband_attenuation,
1935 u16 radio_attenuation,
1940 if (baseband_attenuation == 0xFFFF)
1941 baseband_attenuation = phy->
bbatt;
1942 if (radio_attenuation == 0xFFFF)
1943 radio_attenuation = phy->
rfatt;
1944 if (txpower == 0xFFFF)
1946 phy->
bbatt = baseband_attenuation;
1947 phy->
rfatt = radio_attenuation;
1964 & ~0x0070) | ((txpower << 4) & 0x0070));
1999 if (is_bcm_board_vendor(dev) &&
2000 dev->
dev->bus->boardinfo.type == 0x421 &&
2001 dev->
dev->bus->sprom.board_rev >= 30)
2003 else if (is_bcm_board_vendor(dev) &&
2004 dev->
dev->bus->boardinfo.type == 0x416)
2009 if (is_bcm_board_vendor(dev) &&
2010 dev->
dev->bus->boardinfo.type == 0x421 &&
2011 dev->
dev->bus->sprom.board_rev >= 30)
2019 if (is_bcm_board_vendor(dev) &&
2020 dev->
dev->bus->boardinfo.type == 0x421 &&
2021 dev->
dev->bus->sprom.board_rev >= 30)
2023 else if (is_bcm_board_vendor(dev) &&
2024 dev->
dev->bus->boardinfo.type ==
2027 else if (dev->
dev->bus->chip_id == 0x4320)
2053 if (is_bcm_board_vendor(dev) &&
2054 dev->
dev->bus->boardinfo.type == 0x421) {
2055 if (dev->
dev->bus->sprom.board_rev < 0x43)
2057 else if (dev->
dev->bus->sprom.board_rev < 0x51)
2092 switch (phy->
type) {
2098 (phy->
gmode ? 0x00C0 : 0x0000));
2138 rfoverval & 0xFF73);
2149 switch (phy->
type) {