3 Broadcom B43 wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
7 Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
8 Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
9 Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
24 Boston, MA 02110-1301, USA.
28 #include <linux/delay.h>
30 #include <linux/types.h>
40 static const s8 b43_tssi2dbm_b_table[] = {
41 0x4D, 0x4C, 0x4B, 0x4A,
42 0x4A, 0x49, 0x48, 0x47,
43 0x47, 0x46, 0x45, 0x45,
44 0x44, 0x43, 0x42, 0x42,
45 0x41, 0x40, 0x3F, 0x3E,
46 0x3D, 0x3C, 0x3B, 0x3A,
47 0x39, 0x38, 0x37, 0x36,
48 0x35, 0x34, 0x32, 0x31,
49 0x30, 0x2F, 0x2D, 0x2C,
50 0x2B, 0x29, 0x28, 0x26,
51 0x25, 0x23, 0x21, 0x1F,
52 0x1D, 0x1A, 0x17, 0x14,
53 0x10, 0x0C, 0x06, 0x00,
59 static const s8 b43_tssi2dbm_g_table[] = {
78 const u8 b43_radio_channel_codes_bg[] = {
85 static void b43_phy_initg(struct b43_wldev *dev);
87 /* Reverse the bits of a 4bit value.
88 * Example: 1101 is flipped 1011
90 static u16 flip_4bit(u16 value)
94 B43_WARN_ON(value & ~0x000F);
96 flipped |= (value & 0x0001) << 3;
97 flipped |= (value & 0x0002) << 1;
98 flipped |= (value & 0x0004) >> 1;
99 flipped |= (value & 0x0008) >> 3;
104 static void generate_rfatt_list(struct b43_wldev *dev,
105 struct b43_rfatt_list *list)
107 struct b43_phy *phy = &dev->phy;
109 /* APHY.rev < 5 || GPHY.rev < 6 */
110 static const struct b43_rfatt rfatt_0[] = {
111 {.att = 3,.with_padmix = 0,},
112 {.att = 1,.with_padmix = 0,},
113 {.att = 5,.with_padmix = 0,},
114 {.att = 7,.with_padmix = 0,},
115 {.att = 9,.with_padmix = 0,},
116 {.att = 2,.with_padmix = 0,},
117 {.att = 0,.with_padmix = 0,},
118 {.att = 4,.with_padmix = 0,},
119 {.att = 6,.with_padmix = 0,},
120 {.att = 8,.with_padmix = 0,},
121 {.att = 1,.with_padmix = 1,},
122 {.att = 2,.with_padmix = 1,},
123 {.att = 3,.with_padmix = 1,},
124 {.att = 4,.with_padmix = 1,},
126 /* Radio.rev == 8 && Radio.version == 0x2050 */
127 static const struct b43_rfatt rfatt_1[] = {
128 {.att = 2,.with_padmix = 1,},
129 {.att = 4,.with_padmix = 1,},
130 {.att = 6,.with_padmix = 1,},
131 {.att = 8,.with_padmix = 1,},
132 {.att = 10,.with_padmix = 1,},
133 {.att = 12,.with_padmix = 1,},
134 {.att = 14,.with_padmix = 1,},
137 static const struct b43_rfatt rfatt_2[] = {
138 {.att = 0,.with_padmix = 1,},
139 {.att = 2,.with_padmix = 1,},
140 {.att = 4,.with_padmix = 1,},
141 {.att = 6,.with_padmix = 1,},
142 {.att = 8,.with_padmix = 1,},
143 {.att = 9,.with_padmix = 1,},
144 {.att = 9,.with_padmix = 1,},
147 if ((phy->type == B43_PHYTYPE_A && phy->rev < 5) ||
148 (phy->type == B43_PHYTYPE_G && phy->rev < 6)) {
150 list->list = rfatt_0;
151 list->len = ARRAY_SIZE(rfatt_0);
156 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
158 list->list = rfatt_1;
159 list->len = ARRAY_SIZE(rfatt_1);
165 list->list = rfatt_2;
166 list->len = ARRAY_SIZE(rfatt_2);
171 static void generate_bbatt_list(struct b43_wldev *dev,
172 struct b43_bbatt_list *list)
174 static const struct b43_bbatt bbatt_0[] = {
186 list->list = bbatt_0;
187 list->len = ARRAY_SIZE(bbatt_0);
192 bool b43_has_hardware_pctl(struct b43_phy *phy)
194 if (!phy->hardware_power_control)
211 static void b43_shm_clear_tssi(struct b43_wldev *dev)
213 struct b43_phy *phy = &dev->phy;
217 b43_shm_write16(dev, B43_SHM_SHARED, 0x0068, 0x7F7F);
218 b43_shm_write16(dev, B43_SHM_SHARED, 0x006a, 0x7F7F);
222 b43_shm_write16(dev, B43_SHM_SHARED, 0x0058, 0x7F7F);
223 b43_shm_write16(dev, B43_SHM_SHARED, 0x005a, 0x7F7F);
224 b43_shm_write16(dev, B43_SHM_SHARED, 0x0070, 0x7F7F);
225 b43_shm_write16(dev, B43_SHM_SHARED, 0x0072, 0x7F7F);
230 void b43_raw_phy_lock(struct b43_wldev *dev)
232 struct b43_phy *phy = &dev->phy;
234 B43_WARN_ON(!irqs_disabled());
236 /* We had a check for MACCTL==0 here, but I think that doesn't
237 * make sense, as MACCTL is never 0 when this is called.
239 B43_WARN_ON(b43_read32(dev, B43_MMIO_MACCTL) == 0);
241 if (dev->dev->id.revision < 3) {
242 b43_mac_suspend(dev);
243 spin_lock(&phy->lock);
245 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
246 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
251 void b43_raw_phy_unlock(struct b43_wldev *dev)
253 struct b43_phy *phy = &dev->phy;
255 B43_WARN_ON(!irqs_disabled());
256 if (dev->dev->id.revision < 3) {
258 spin_unlock(&phy->lock);
262 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
263 b43_power_saving_ctl_bits(dev, 0);
268 /* Different PHYs require different register routing flags.
269 * This adjusts (and does sanity checks on) the routing flags.
271 static inline u16 adjust_phyreg_for_phytype(struct b43_phy *phy,
272 u16 offset, struct b43_wldev *dev)
274 if (phy->type == B43_PHYTYPE_A) {
275 /* OFDM registers are base-registers for the A-PHY. */
276 offset &= ~B43_PHYROUTE_OFDM_GPHY;
278 if (offset & B43_PHYROUTE_EXT_GPHY) {
279 /* Ext-G registers are only available on G-PHYs */
280 if (phy->type != B43_PHYTYPE_G) {
281 b43dbg(dev->wl, "EXT-G PHY access at "
282 "0x%04X on %u type PHY\n", offset, phy->type);
289 u16 b43_phy_read(struct b43_wldev * dev, u16 offset)
291 struct b43_phy *phy = &dev->phy;
293 offset = adjust_phyreg_for_phytype(phy, offset, dev);
294 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
295 return b43_read16(dev, B43_MMIO_PHY_DATA);
298 void b43_phy_write(struct b43_wldev *dev, u16 offset, u16 val)
300 struct b43_phy *phy = &dev->phy;
302 offset = adjust_phyreg_for_phytype(phy, offset, dev);
303 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
305 b43_write16(dev, B43_MMIO_PHY_DATA, val);
308 /* Adjust the transmission power output (G-PHY) */
309 void b43_set_txpower_g(struct b43_wldev *dev,
310 const struct b43_bbatt *bbatt,
311 const struct b43_rfatt *rfatt, u8 tx_control)
313 struct b43_phy *phy = &dev->phy;
314 struct b43_txpower_lo_control *lo = phy->lo_control;
316 u16 tx_bias, tx_magn;
320 tx_bias = lo->tx_bias;
321 tx_magn = lo->tx_magn;
322 if (unlikely(tx_bias == 0xFF))
325 /* Save the values for later */
326 phy->tx_control = tx_control;
327 memcpy(&phy->rfatt, rfatt, sizeof(*rfatt));
328 memcpy(&phy->bbatt, bbatt, sizeof(*bbatt));
330 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
331 b43dbg(dev->wl, "Tuning TX-power to bbatt(%u), "
332 "rfatt(%u), tx_control(0x%02X), "
333 "tx_bias(0x%02X), tx_magn(0x%02X)\n",
334 bb, rf, tx_control, tx_bias, tx_magn);
337 b43_phy_set_baseband_attenuation(dev, bb);
338 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_RFATT, rf);
339 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
340 b43_radio_write16(dev, 0x43,
341 (rf & 0x000F) | (tx_control & 0x0070));
343 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
344 & 0xFFF0) | (rf & 0x000F));
345 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
346 & ~0x0070) | (tx_control &
349 if (has_tx_magnification(phy)) {
350 b43_radio_write16(dev, 0x52, tx_magn | tx_bias);
352 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
353 & 0xFFF0) | (tx_bias & 0x000F));
355 if (phy->type == B43_PHYTYPE_G)
356 b43_lo_g_adjust(dev);
359 static void default_baseband_attenuation(struct b43_wldev *dev,
360 struct b43_bbatt *bb)
362 struct b43_phy *phy = &dev->phy;
364 if (phy->radio_ver == 0x2050 && phy->radio_rev < 6)
370 static void default_radio_attenuation(struct b43_wldev *dev,
371 struct b43_rfatt *rf)
373 struct ssb_bus *bus = dev->dev->bus;
374 struct b43_phy *phy = &dev->phy;
378 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM &&
379 bus->boardinfo.type == SSB_BOARD_BCM4309G) {
380 if (bus->boardinfo.rev < 0x43) {
383 } else if (bus->boardinfo.rev < 0x51) {
389 if (phy->type == B43_PHYTYPE_A) {
394 switch (phy->radio_ver) {
396 switch (phy->radio_rev) {
403 switch (phy->radio_rev) {
408 if (phy->type == B43_PHYTYPE_G) {
409 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
410 && bus->boardinfo.type == SSB_BOARD_BCM4309G
411 && bus->boardinfo.rev >= 30)
413 else if (bus->boardinfo.vendor ==
415 && bus->boardinfo.type ==
421 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
422 && bus->boardinfo.type == SSB_BOARD_BCM4309G
423 && bus->boardinfo.rev >= 30)
430 if (phy->type == B43_PHYTYPE_G) {
431 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
432 && bus->boardinfo.type == SSB_BOARD_BCM4309G
433 && bus->boardinfo.rev >= 30)
435 else if (bus->boardinfo.vendor ==
437 && bus->boardinfo.type ==
440 else if (bus->chip_id == 0x4320)
471 static u16 default_tx_control(struct b43_wldev *dev)
473 struct b43_phy *phy = &dev->phy;
475 if (phy->radio_ver != 0x2050)
477 if (phy->radio_rev == 1)
478 return B43_TXCTL_PA2DB | B43_TXCTL_TXMIX;
479 if (phy->radio_rev < 6)
480 return B43_TXCTL_PA2DB;
481 if (phy->radio_rev == 8)
482 return B43_TXCTL_TXMIX;
486 /* This func is called "PHY calibrate" in the specs... */
487 void b43_phy_early_init(struct b43_wldev *dev)
489 struct b43_phy *phy = &dev->phy;
490 struct b43_txpower_lo_control *lo = phy->lo_control;
492 default_baseband_attenuation(dev, &phy->bbatt);
493 default_radio_attenuation(dev, &phy->rfatt);
494 phy->tx_control = (default_tx_control(dev) << 4);
496 /* Commit previous writes */
497 b43_read32(dev, B43_MMIO_MACCTL);
499 if (phy->type == B43_PHYTYPE_B || phy->type == B43_PHYTYPE_G) {
500 generate_rfatt_list(dev, &lo->rfatt_list);
501 generate_bbatt_list(dev, &lo->bbatt_list);
503 if (phy->type == B43_PHYTYPE_G && phy->rev == 1) {
504 /* Workaround: Temporarly disable gmode through the early init
505 * phase, as the gmode stuff is not needed for phy rev 1 */
507 b43_wireless_core_reset(dev, 0);
510 b43_wireless_core_reset(dev, B43_TMSLOW_GMODE);
514 /* GPHY_TSSI_Power_Lookup_Table_Init */
515 static void b43_gphy_tssi_power_lt_init(struct b43_wldev *dev)
517 struct b43_phy *phy = &dev->phy;
521 for (i = 0; i < 32; i++)
522 b43_ofdmtab_write16(dev, 0x3C20, i, phy->tssi2dbm[i]);
523 for (i = 32; i < 64; i++)
524 b43_ofdmtab_write16(dev, 0x3C00, i - 32, phy->tssi2dbm[i]);
525 for (i = 0; i < 64; i += 2) {
526 value = (u16) phy->tssi2dbm[i];
527 value |= ((u16) phy->tssi2dbm[i + 1]) << 8;
528 b43_phy_write(dev, 0x380 + (i / 2), value);
532 /* GPHY_Gain_Lookup_Table_Init */
533 static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
535 struct b43_phy *phy = &dev->phy;
536 struct b43_txpower_lo_control *lo = phy->lo_control;
541 if (!lo->lo_measured) {
542 b43_phy_write(dev, 0x3FF, 0);
546 for (rf = 0; rf < lo->rfatt_list.len; rf++) {
547 for (bb = 0; bb < lo->bbatt_list.len; bb++) {
548 if (nr_written >= 0x40)
550 tmp = lo->bbatt_list.list[bb].att;
552 if (phy->radio_rev == 8)
556 tmp |= lo->rfatt_list.list[rf].att;
557 b43_phy_write(dev, 0x3C0 + nr_written, tmp);
563 /* GPHY_DC_Lookup_Table */
564 void b43_gphy_dc_lt_init(struct b43_wldev *dev)
566 struct b43_phy *phy = &dev->phy;
567 struct b43_txpower_lo_control *lo = phy->lo_control;
568 struct b43_loctl *loctl0;
569 struct b43_loctl *loctl1;
571 int rf_offset, bb_offset;
574 for (i = 0; i < lo->rfatt_list.len + lo->bbatt_list.len; i += 2) {
575 rf_offset = i / lo->rfatt_list.len;
576 bb_offset = i % lo->rfatt_list.len;
578 loctl0 = b43_get_lo_g_ctl(dev, &lo->rfatt_list.list[rf_offset],
579 &lo->bbatt_list.list[bb_offset]);
580 if (i + 1 < lo->rfatt_list.len * lo->bbatt_list.len) {
581 rf_offset = (i + 1) / lo->rfatt_list.len;
582 bb_offset = (i + 1) % lo->rfatt_list.len;
585 b43_get_lo_g_ctl(dev,
586 &lo->rfatt_list.list[rf_offset],
587 &lo->bbatt_list.list[bb_offset]);
591 tmp = ((u16) loctl0->q & 0xF);
592 tmp |= ((u16) loctl0->i & 0xF) << 4;
593 tmp |= ((u16) loctl1->q & 0xF) << 8;
594 tmp |= ((u16) loctl1->i & 0xF) << 12; //FIXME?
595 b43_phy_write(dev, 0x3A0 + (i / 2), tmp);
599 static void hardware_pctl_init_aphy(struct b43_wldev *dev)
604 static void hardware_pctl_init_gphy(struct b43_wldev *dev)
606 struct b43_phy *phy = &dev->phy;
608 b43_phy_write(dev, 0x0036, (b43_phy_read(dev, 0x0036) & 0xFFC0)
609 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
610 b43_phy_write(dev, 0x0478, (b43_phy_read(dev, 0x0478) & 0xFF00)
611 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
612 b43_gphy_tssi_power_lt_init(dev);
613 b43_gphy_gain_lt_init(dev);
614 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) & 0xFFBF);
615 b43_phy_write(dev, 0x0014, 0x0000);
617 B43_WARN_ON(phy->rev < 6);
618 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
620 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
622 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801)
625 b43_gphy_dc_lt_init(dev);
628 /* HardwarePowerControl init for A and G PHY */
629 static void b43_hardware_pctl_init(struct b43_wldev *dev)
631 struct b43_phy *phy = &dev->phy;
633 if (!b43_has_hardware_pctl(phy)) {
634 /* No hardware power control */
635 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_HWPCTL);
638 /* Init the hwpctl related hardware */
641 hardware_pctl_init_aphy(dev);
644 hardware_pctl_init_gphy(dev);
649 /* Enable hardware pctl in firmware. */
650 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL);
653 static void b43_hardware_pctl_early_init(struct b43_wldev *dev)
655 struct b43_phy *phy = &dev->phy;
657 if (!b43_has_hardware_pctl(phy)) {
658 b43_phy_write(dev, 0x047A, 0xC111);
662 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036) & 0xFEFF);
663 b43_phy_write(dev, 0x002F, 0x0202);
664 b43_phy_write(dev, 0x047C, b43_phy_read(dev, 0x047C) | 0x0002);
665 b43_phy_write(dev, 0x047A, b43_phy_read(dev, 0x047A) | 0xF000);
666 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
667 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
669 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
671 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
673 b43_phy_write(dev, 0x002E, 0xC07F);
674 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
677 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
679 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
681 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
683 b43_phy_write(dev, 0x004F, b43_phy_read(dev, 0x004F)
685 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
687 b43_phy_write(dev, 0x002E, 0xC07F);
688 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
693 /* Intialize B/G PHY power control
694 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
696 static void b43_phy_init_pctl(struct b43_wldev *dev)
698 struct ssb_bus *bus = dev->dev->bus;
699 struct b43_phy *phy = &dev->phy;
700 struct b43_rfatt old_rfatt;
701 struct b43_bbatt old_bbatt;
702 u8 old_tx_control = 0;
704 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
705 (bus->boardinfo.type == SSB_BOARD_BU4306))
708 b43_phy_write(dev, 0x0028, 0x8018);
710 /* This does something with the Analog... */
711 b43_write16(dev, B43_MMIO_PHY0, b43_read16(dev, B43_MMIO_PHY0)
714 if (phy->type == B43_PHYTYPE_G && !phy->gmode)
716 b43_hardware_pctl_early_init(dev);
717 if (phy->cur_idle_tssi == 0) {
718 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
719 b43_radio_write16(dev, 0x0076,
720 (b43_radio_read16(dev, 0x0076)
723 struct b43_rfatt rfatt;
724 struct b43_bbatt bbatt;
726 memcpy(&old_rfatt, &phy->rfatt, sizeof(old_rfatt));
727 memcpy(&old_bbatt, &phy->bbatt, sizeof(old_bbatt));
728 old_tx_control = phy->tx_control;
731 if (phy->radio_rev == 8) {
733 rfatt.with_padmix = 1;
736 rfatt.with_padmix = 0;
738 b43_set_txpower_g(dev, &bbatt, &rfatt, 0);
740 b43_dummy_transmission(dev);
741 phy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_ITSSI);
743 /* Current-Idle-TSSI sanity check. */
744 if (abs(phy->cur_idle_tssi - phy->tgt_idle_tssi) >= 20) {
746 "!WARNING! Idle-TSSI phy->cur_idle_tssi "
747 "measuring failed. (cur=%d, tgt=%d). Disabling TX power "
748 "adjustment.\n", phy->cur_idle_tssi,
750 phy->cur_idle_tssi = 0;
753 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
754 b43_radio_write16(dev, 0x0076,
755 b43_radio_read16(dev, 0x0076)
758 b43_set_txpower_g(dev, &old_bbatt,
759 &old_rfatt, old_tx_control);
762 b43_hardware_pctl_init(dev);
763 b43_shm_clear_tssi(dev);
766 static void b43_phy_rssiagc(struct b43_wldev *dev, u8 enable)
770 if (dev->phy.rev < 3) {
772 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++) {
773 b43_ofdmtab_write16(dev,
774 B43_OFDMTAB_LNAHPFGAIN1, i, 0xFFF8);
775 b43_ofdmtab_write16(dev,
776 B43_OFDMTAB_WRSSI, i, 0xFFF8);
779 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++) {
780 b43_ofdmtab_write16(dev,
781 B43_OFDMTAB_LNAHPFGAIN1, i, b43_tab_rssiagc1[i]);
782 b43_ofdmtab_write16(dev,
783 B43_OFDMTAB_WRSSI, i, b43_tab_rssiagc1[i]);
787 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++)
788 b43_ofdmtab_write16(dev,
789 B43_OFDMTAB_WRSSI, i, 0x0820);
791 for (i = 0; i < B43_TAB_RSSIAGC2_SIZE; i++)
792 b43_ofdmtab_write16(dev,
793 B43_OFDMTAB_WRSSI, i, b43_tab_rssiagc2[i]);
797 static void b43_phy_ww(struct b43_wldev *dev)
799 u16 b, curr_s, best_s = 0xFFFF;
802 b43_phy_write(dev, B43_PHY_CRS0,
803 b43_phy_read(dev, B43_PHY_CRS0) & ~B43_PHY_CRS0_EN);
804 b43_phy_write(dev, B43_PHY_OFDM(0x1B),
805 b43_phy_read(dev, B43_PHY_OFDM(0x1B)) | 0x1000);
806 b43_phy_write(dev, B43_PHY_OFDM(0x82),
807 (b43_phy_read(dev, B43_PHY_OFDM(0x82)) & 0xF0FF) | 0x0300);
808 b43_radio_write16(dev, 0x0009,
809 b43_radio_read16(dev, 0x0009) | 0x0080);
810 b43_radio_write16(dev, 0x0012,
811 (b43_radio_read16(dev, 0x0012) & 0xFFFC) | 0x0002);
812 b43_wa_initgains(dev);
813 b43_phy_write(dev, B43_PHY_OFDM(0xBA), 0x3ED5);
814 b = b43_phy_read(dev, B43_PHY_PWRDOWN);
815 b43_phy_write(dev, B43_PHY_PWRDOWN, (b & 0xFFF8) | 0x0005);
816 b43_radio_write16(dev, 0x0004,
817 b43_radio_read16(dev, 0x0004) | 0x0004);
818 for (i = 0x10; i <= 0x20; i++) {
819 b43_radio_write16(dev, 0x0013, i);
820 curr_s = b43_phy_read(dev, B43_PHY_OTABLEQ) & 0x00FF;
824 } else if (curr_s >= 0x0080)
825 curr_s = 0x0100 - curr_s;
829 b43_phy_write(dev, B43_PHY_PWRDOWN, b);
830 b43_radio_write16(dev, 0x0004,
831 b43_radio_read16(dev, 0x0004) & 0xFFFB);
832 b43_radio_write16(dev, 0x0013, best_s);
833 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1_R1, 0, 0xFFEC);
834 b43_phy_write(dev, B43_PHY_OFDM(0xB7), 0x1E80);
835 b43_phy_write(dev, B43_PHY_OFDM(0xB6), 0x1C00);
836 b43_phy_write(dev, B43_PHY_OFDM(0xB5), 0x0EC0);
837 b43_phy_write(dev, B43_PHY_OFDM(0xB2), 0x00C0);
838 b43_phy_write(dev, B43_PHY_OFDM(0xB9), 0x1FFF);
839 b43_phy_write(dev, B43_PHY_OFDM(0xBB),
840 (b43_phy_read(dev, B43_PHY_OFDM(0xBB)) & 0xF000) | 0x0053);
841 b43_phy_write(dev, B43_PHY_OFDM61,
842 (b43_phy_read(dev, B43_PHY_OFDM61 & 0xFE1F)) | 0x0120);
843 b43_phy_write(dev, B43_PHY_OFDM(0x13),
844 (b43_phy_read(dev, B43_PHY_OFDM(0x13)) & 0x0FFF) | 0x3000);
845 b43_phy_write(dev, B43_PHY_OFDM(0x14),
846 (b43_phy_read(dev, B43_PHY_OFDM(0x14)) & 0x0FFF) | 0x3000);
847 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 6, 0x0017);
848 for (i = 0; i < 6; i++)
849 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, i, 0x000F);
850 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0D, 0x000E);
851 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0E, 0x0011);
852 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0F, 0x0013);
853 b43_phy_write(dev, B43_PHY_OFDM(0x33), 0x5030);
854 b43_phy_write(dev, B43_PHY_CRS0,
855 b43_phy_read(dev, B43_PHY_CRS0) | B43_PHY_CRS0_EN);
858 /* Initialize APHY. This is also called for the GPHY in some cases. */
859 static void b43_phy_inita(struct b43_wldev *dev)
861 struct ssb_bus *bus = dev->dev->bus;
862 struct b43_phy *phy = &dev->phy;
867 if (phy->type == B43_PHYTYPE_A)
868 b43_phy_write(dev, B43_PHY_OFDM(0x1B),
869 b43_phy_read(dev, B43_PHY_OFDM(0x1B)) & ~0x1000);
870 if (b43_phy_read(dev, B43_PHY_ENCORE) & B43_PHY_ENCORE_EN)
871 b43_phy_write(dev, B43_PHY_ENCORE,
872 b43_phy_read(dev, B43_PHY_ENCORE) | 0x0010);
874 b43_phy_write(dev, B43_PHY_ENCORE,
875 b43_phy_read(dev, B43_PHY_ENCORE) & ~0x1010);
880 if (phy->type == B43_PHYTYPE_A) {
881 if (phy->gmode && (phy->rev < 3))
882 b43_phy_write(dev, 0x0034,
883 b43_phy_read(dev, 0x0034) | 0x0001);
884 b43_phy_rssiagc(dev, 0);
886 b43_phy_write(dev, B43_PHY_CRS0,
887 b43_phy_read(dev, B43_PHY_CRS0) | B43_PHY_CRS0_EN);
889 b43_radio_init2060(dev);
891 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
892 ((bus->boardinfo.type == SSB_BOARD_BU4306) ||
893 (bus->boardinfo.type == SSB_BOARD_BU4309))) {
900 hardware_pctl_init_aphy(dev);
902 //TODO: radar detection
905 if ((phy->type == B43_PHYTYPE_G) &&
906 (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)) {
907 b43_phy_write(dev, B43_PHY_OFDM(0x6E),
908 (b43_phy_read(dev, B43_PHY_OFDM(0x6E))
913 static void b43_phy_initb2(struct b43_wldev *dev)
915 struct b43_phy *phy = &dev->phy;
918 b43_write16(dev, 0x03EC, 0x3F22);
919 b43_phy_write(dev, 0x0020, 0x301C);
920 b43_phy_write(dev, 0x0026, 0x0000);
921 b43_phy_write(dev, 0x0030, 0x00C6);
922 b43_phy_write(dev, 0x0088, 0x3E00);
924 for (offset = 0x0089; offset < 0x00A7; offset++) {
925 b43_phy_write(dev, offset, val);
928 b43_phy_write(dev, 0x03E4, 0x3000);
929 b43_radio_selectchannel(dev, phy->channel, 0);
930 if (phy->radio_ver != 0x2050) {
931 b43_radio_write16(dev, 0x0075, 0x0080);
932 b43_radio_write16(dev, 0x0079, 0x0081);
934 b43_radio_write16(dev, 0x0050, 0x0020);
935 b43_radio_write16(dev, 0x0050, 0x0023);
936 if (phy->radio_ver == 0x2050) {
937 b43_radio_write16(dev, 0x0050, 0x0020);
938 b43_radio_write16(dev, 0x005A, 0x0070);
939 b43_radio_write16(dev, 0x005B, 0x007B);
940 b43_radio_write16(dev, 0x005C, 0x00B0);
941 b43_radio_write16(dev, 0x007A, 0x000F);
942 b43_phy_write(dev, 0x0038, 0x0677);
943 b43_radio_init2050(dev);
945 b43_phy_write(dev, 0x0014, 0x0080);
946 b43_phy_write(dev, 0x0032, 0x00CA);
947 b43_phy_write(dev, 0x0032, 0x00CC);
948 b43_phy_write(dev, 0x0035, 0x07C2);
949 b43_lo_b_measure(dev);
950 b43_phy_write(dev, 0x0026, 0xCC00);
951 if (phy->radio_ver != 0x2050)
952 b43_phy_write(dev, 0x0026, 0xCE00);
953 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1000);
954 b43_phy_write(dev, 0x002A, 0x88A3);
955 if (phy->radio_ver != 0x2050)
956 b43_phy_write(dev, 0x002A, 0x88C2);
957 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
958 b43_phy_init_pctl(dev);
961 static void b43_phy_initb4(struct b43_wldev *dev)
963 struct b43_phy *phy = &dev->phy;
966 b43_write16(dev, 0x03EC, 0x3F22);
967 b43_phy_write(dev, 0x0020, 0x301C);
968 b43_phy_write(dev, 0x0026, 0x0000);
969 b43_phy_write(dev, 0x0030, 0x00C6);
970 b43_phy_write(dev, 0x0088, 0x3E00);
972 for (offset = 0x0089; offset < 0x00A7; offset++) {
973 b43_phy_write(dev, offset, val);
976 b43_phy_write(dev, 0x03E4, 0x3000);
977 b43_radio_selectchannel(dev, phy->channel, 0);
978 if (phy->radio_ver != 0x2050) {
979 b43_radio_write16(dev, 0x0075, 0x0080);
980 b43_radio_write16(dev, 0x0079, 0x0081);
982 b43_radio_write16(dev, 0x0050, 0x0020);
983 b43_radio_write16(dev, 0x0050, 0x0023);
984 if (phy->radio_ver == 0x2050) {
985 b43_radio_write16(dev, 0x0050, 0x0020);
986 b43_radio_write16(dev, 0x005A, 0x0070);
987 b43_radio_write16(dev, 0x005B, 0x007B);
988 b43_radio_write16(dev, 0x005C, 0x00B0);
989 b43_radio_write16(dev, 0x007A, 0x000F);
990 b43_phy_write(dev, 0x0038, 0x0677);
991 b43_radio_init2050(dev);
993 b43_phy_write(dev, 0x0014, 0x0080);
994 b43_phy_write(dev, 0x0032, 0x00CA);
995 if (phy->radio_ver == 0x2050)
996 b43_phy_write(dev, 0x0032, 0x00E0);
997 b43_phy_write(dev, 0x0035, 0x07C2);
999 b43_lo_b_measure(dev);
1001 b43_phy_write(dev, 0x0026, 0xCC00);
1002 if (phy->radio_ver == 0x2050)
1003 b43_phy_write(dev, 0x0026, 0xCE00);
1004 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1100);
1005 b43_phy_write(dev, 0x002A, 0x88A3);
1006 if (phy->radio_ver == 0x2050)
1007 b43_phy_write(dev, 0x002A, 0x88C2);
1008 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1009 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1010 b43_calc_nrssi_slope(dev);
1011 b43_calc_nrssi_threshold(dev);
1013 b43_phy_init_pctl(dev);
1016 static void b43_phy_initb5(struct b43_wldev *dev)
1018 struct ssb_bus *bus = dev->dev->bus;
1019 struct b43_phy *phy = &dev->phy;
1023 if (phy->analog == 1) {
1024 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
1027 if ((bus->boardinfo.vendor != SSB_BOARDVENDOR_BCM) &&
1028 (bus->boardinfo.type != SSB_BOARD_BU4306)) {
1030 for (offset = 0x00A8; offset < 0x00C7; offset++) {
1031 b43_phy_write(dev, offset, value);
1035 b43_phy_write(dev, 0x0035, (b43_phy_read(dev, 0x0035) & 0xF0FF)
1037 if (phy->radio_ver == 0x2050)
1038 b43_phy_write(dev, 0x0038, 0x0667);
1040 if (phy->gmode || phy->rev >= 2) {
1041 if (phy->radio_ver == 0x2050) {
1042 b43_radio_write16(dev, 0x007A,
1043 b43_radio_read16(dev, 0x007A)
1045 b43_radio_write16(dev, 0x0051,
1046 b43_radio_read16(dev, 0x0051)
1049 b43_write16(dev, B43_MMIO_PHY_RADIO, 0x0000);
1051 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1052 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1054 b43_phy_write(dev, 0x001C, 0x186A);
1056 b43_phy_write(dev, 0x0013,
1057 (b43_phy_read(dev, 0x0013) & 0x00FF) | 0x1900);
1058 b43_phy_write(dev, 0x0035,
1059 (b43_phy_read(dev, 0x0035) & 0xFFC0) | 0x0064);
1060 b43_phy_write(dev, 0x005D,
1061 (b43_phy_read(dev, 0x005D) & 0xFF80) | 0x000A);
1064 if (dev->bad_frames_preempt) {
1065 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
1067 B43_PHY_RADIO_BITFIELD) | (1 << 11));
1070 if (phy->analog == 1) {
1071 b43_phy_write(dev, 0x0026, 0xCE00);
1072 b43_phy_write(dev, 0x0021, 0x3763);
1073 b43_phy_write(dev, 0x0022, 0x1BC3);
1074 b43_phy_write(dev, 0x0023, 0x06F9);
1075 b43_phy_write(dev, 0x0024, 0x037E);
1077 b43_phy_write(dev, 0x0026, 0xCC00);
1078 b43_phy_write(dev, 0x0030, 0x00C6);
1079 b43_write16(dev, 0x03EC, 0x3F22);
1081 if (phy->analog == 1)
1082 b43_phy_write(dev, 0x0020, 0x3E1C);
1084 b43_phy_write(dev, 0x0020, 0x301C);
1086 if (phy->analog == 0)
1087 b43_write16(dev, 0x03E4, 0x3000);
1089 old_channel = phy->channel;
1090 /* Force to channel 7, even if not supported. */
1091 b43_radio_selectchannel(dev, 7, 0);
1093 if (phy->radio_ver != 0x2050) {
1094 b43_radio_write16(dev, 0x0075, 0x0080);
1095 b43_radio_write16(dev, 0x0079, 0x0081);
1098 b43_radio_write16(dev, 0x0050, 0x0020);
1099 b43_radio_write16(dev, 0x0050, 0x0023);
1101 if (phy->radio_ver == 0x2050) {
1102 b43_radio_write16(dev, 0x0050, 0x0020);
1103 b43_radio_write16(dev, 0x005A, 0x0070);
1106 b43_radio_write16(dev, 0x005B, 0x007B);
1107 b43_radio_write16(dev, 0x005C, 0x00B0);
1109 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0007);
1111 b43_radio_selectchannel(dev, old_channel, 0);
1113 b43_phy_write(dev, 0x0014, 0x0080);
1114 b43_phy_write(dev, 0x0032, 0x00CA);
1115 b43_phy_write(dev, 0x002A, 0x88A3);
1117 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1119 if (phy->radio_ver == 0x2050)
1120 b43_radio_write16(dev, 0x005D, 0x000D);
1122 b43_write16(dev, 0x03E4, (b43_read16(dev, 0x03E4) & 0xFFC0) | 0x0004);
1125 static void b43_phy_initb6(struct b43_wldev *dev)
1127 struct b43_phy *phy = &dev->phy;
1131 b43_phy_write(dev, 0x003E, 0x817A);
1132 b43_radio_write16(dev, 0x007A,
1133 (b43_radio_read16(dev, 0x007A) | 0x0058));
1134 if (phy->radio_rev == 4 || phy->radio_rev == 5) {
1135 b43_radio_write16(dev, 0x51, 0x37);
1136 b43_radio_write16(dev, 0x52, 0x70);
1137 b43_radio_write16(dev, 0x53, 0xB3);
1138 b43_radio_write16(dev, 0x54, 0x9B);
1139 b43_radio_write16(dev, 0x5A, 0x88);
1140 b43_radio_write16(dev, 0x5B, 0x88);
1141 b43_radio_write16(dev, 0x5D, 0x88);
1142 b43_radio_write16(dev, 0x5E, 0x88);
1143 b43_radio_write16(dev, 0x7D, 0x88);
1144 b43_hf_write(dev, b43_hf_read(dev)
1145 | B43_HF_TSSIRPSMW);
1147 B43_WARN_ON(phy->radio_rev == 6 || phy->radio_rev == 7); /* We had code for these revs here... */
1148 if (phy->radio_rev == 8) {
1149 b43_radio_write16(dev, 0x51, 0);
1150 b43_radio_write16(dev, 0x52, 0x40);
1151 b43_radio_write16(dev, 0x53, 0xB7);
1152 b43_radio_write16(dev, 0x54, 0x98);
1153 b43_radio_write16(dev, 0x5A, 0x88);
1154 b43_radio_write16(dev, 0x5B, 0x6B);
1155 b43_radio_write16(dev, 0x5C, 0x0F);
1156 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_ALTIQ) {
1157 b43_radio_write16(dev, 0x5D, 0xFA);
1158 b43_radio_write16(dev, 0x5E, 0xD8);
1160 b43_radio_write16(dev, 0x5D, 0xF5);
1161 b43_radio_write16(dev, 0x5E, 0xB8);
1163 b43_radio_write16(dev, 0x0073, 0x0003);
1164 b43_radio_write16(dev, 0x007D, 0x00A8);
1165 b43_radio_write16(dev, 0x007C, 0x0001);
1166 b43_radio_write16(dev, 0x007E, 0x0008);
1169 for (offset = 0x0088; offset < 0x0098; offset++) {
1170 b43_phy_write(dev, offset, val);
1174 for (offset = 0x0098; offset < 0x00A8; offset++) {
1175 b43_phy_write(dev, offset, val);
1179 for (offset = 0x00A8; offset < 0x00C8; offset++) {
1180 b43_phy_write(dev, offset, (val & 0x3F3F));
1183 if (phy->type == B43_PHYTYPE_G) {
1184 b43_radio_write16(dev, 0x007A,
1185 b43_radio_read16(dev, 0x007A) | 0x0020);
1186 b43_radio_write16(dev, 0x0051,
1187 b43_radio_read16(dev, 0x0051) | 0x0004);
1188 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1189 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1190 b43_phy_write(dev, 0x5B, 0);
1191 b43_phy_write(dev, 0x5C, 0);
1194 old_channel = phy->channel;
1195 if (old_channel >= 8)
1196 b43_radio_selectchannel(dev, 1, 0);
1198 b43_radio_selectchannel(dev, 13, 0);
1200 b43_radio_write16(dev, 0x0050, 0x0020);
1201 b43_radio_write16(dev, 0x0050, 0x0023);
1203 if (phy->radio_rev < 6 || phy->radio_rev == 8) {
1204 b43_radio_write16(dev, 0x7C, (b43_radio_read16(dev, 0x7C)
1206 b43_radio_write16(dev, 0x50, 0x20);
1208 if (phy->radio_rev <= 2) {
1209 b43_radio_write16(dev, 0x7C, 0x20);
1210 b43_radio_write16(dev, 0x5A, 0x70);
1211 b43_radio_write16(dev, 0x5B, 0x7B);
1212 b43_radio_write16(dev, 0x5C, 0xB0);
1214 b43_radio_write16(dev, 0x007A,
1215 (b43_radio_read16(dev, 0x007A) & 0x00F8) | 0x0007);
1217 b43_radio_selectchannel(dev, old_channel, 0);
1219 b43_phy_write(dev, 0x0014, 0x0200);
1220 if (phy->radio_rev >= 6)
1221 b43_phy_write(dev, 0x2A, 0x88C2);
1223 b43_phy_write(dev, 0x2A, 0x8AC0);
1224 b43_phy_write(dev, 0x0038, 0x0668);
1225 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1226 if (phy->radio_rev <= 5) {
1227 b43_phy_write(dev, 0x5D, (b43_phy_read(dev, 0x5D)
1228 & 0xFF80) | 0x0003);
1230 if (phy->radio_rev <= 2)
1231 b43_radio_write16(dev, 0x005D, 0x000D);
1233 if (phy->analog == 4) {
1234 b43_write16(dev, 0x3E4, 9);
1235 b43_phy_write(dev, 0x61, b43_phy_read(dev, 0x61)
1238 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0)
1241 if (phy->type == B43_PHYTYPE_B) {
1242 b43_write16(dev, 0x03E6, 0x8140);
1243 b43_phy_write(dev, 0x0016, 0x0410);
1244 b43_phy_write(dev, 0x0017, 0x0820);
1245 b43_phy_write(dev, 0x0062, 0x0007);
1246 b43_radio_init2050(dev);
1247 b43_lo_g_measure(dev);
1248 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1249 b43_calc_nrssi_slope(dev);
1250 b43_calc_nrssi_threshold(dev);
1252 b43_phy_init_pctl(dev);
1253 } else if (phy->type == B43_PHYTYPE_G)
1254 b43_write16(dev, 0x03E6, 0x0);
1257 static void b43_calc_loopback_gain(struct b43_wldev *dev)
1259 struct b43_phy *phy = &dev->phy;
1260 u16 backup_phy[16] = { 0 };
1261 u16 backup_radio[3];
1263 u16 i, j, loop_i_max;
1265 u16 loop1_outer_done, loop1_inner_done;
1267 backup_phy[0] = b43_phy_read(dev, B43_PHY_CRS0);
1268 backup_phy[1] = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
1269 backup_phy[2] = b43_phy_read(dev, B43_PHY_RFOVER);
1270 backup_phy[3] = b43_phy_read(dev, B43_PHY_RFOVERVAL);
1271 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1272 backup_phy[4] = b43_phy_read(dev, B43_PHY_ANALOGOVER);
1273 backup_phy[5] = b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
1275 backup_phy[6] = b43_phy_read(dev, B43_PHY_BASE(0x5A));
1276 backup_phy[7] = b43_phy_read(dev, B43_PHY_BASE(0x59));
1277 backup_phy[8] = b43_phy_read(dev, B43_PHY_BASE(0x58));
1278 backup_phy[9] = b43_phy_read(dev, B43_PHY_BASE(0x0A));
1279 backup_phy[10] = b43_phy_read(dev, B43_PHY_BASE(0x03));
1280 backup_phy[11] = b43_phy_read(dev, B43_PHY_LO_MASK);
1281 backup_phy[12] = b43_phy_read(dev, B43_PHY_LO_CTL);
1282 backup_phy[13] = b43_phy_read(dev, B43_PHY_BASE(0x2B));
1283 backup_phy[14] = b43_phy_read(dev, B43_PHY_PGACTL);
1284 backup_phy[15] = b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
1285 backup_bband = phy->bbatt.att;
1286 backup_radio[0] = b43_radio_read16(dev, 0x52);
1287 backup_radio[1] = b43_radio_read16(dev, 0x43);
1288 backup_radio[2] = b43_radio_read16(dev, 0x7A);
1290 b43_phy_write(dev, B43_PHY_CRS0,
1291 b43_phy_read(dev, B43_PHY_CRS0) & 0x3FFF);
1292 b43_phy_write(dev, B43_PHY_CCKBBANDCFG,
1293 b43_phy_read(dev, B43_PHY_CCKBBANDCFG) | 0x8000);
1294 b43_phy_write(dev, B43_PHY_RFOVER,
1295 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0002);
1296 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1297 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFD);
1298 b43_phy_write(dev, B43_PHY_RFOVER,
1299 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0001);
1300 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1301 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFE);
1302 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1303 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1304 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0001);
1305 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1307 B43_PHY_ANALOGOVERVAL) & 0xFFFE);
1308 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1309 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0002);
1310 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1312 B43_PHY_ANALOGOVERVAL) & 0xFFFD);
1314 b43_phy_write(dev, B43_PHY_RFOVER,
1315 b43_phy_read(dev, B43_PHY_RFOVER) | 0x000C);
1316 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1317 b43_phy_read(dev, B43_PHY_RFOVERVAL) | 0x000C);
1318 b43_phy_write(dev, B43_PHY_RFOVER,
1319 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0030);
1320 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1321 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1324 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0780);
1325 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
1326 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
1328 b43_phy_write(dev, B43_PHY_BASE(0x0A),
1329 b43_phy_read(dev, B43_PHY_BASE(0x0A)) | 0x2000);
1330 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1331 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1332 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0004);
1333 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1335 B43_PHY_ANALOGOVERVAL) & 0xFFFB);
1337 b43_phy_write(dev, B43_PHY_BASE(0x03),
1338 (b43_phy_read(dev, B43_PHY_BASE(0x03))
1341 if (phy->radio_rev == 8) {
1342 b43_radio_write16(dev, 0x43, 0x000F);
1344 b43_radio_write16(dev, 0x52, 0);
1345 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
1348 b43_phy_set_baseband_attenuation(dev, 11);
1351 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
1353 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
1354 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
1356 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1357 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1359 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1360 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1363 b43_phy_write(dev, B43_PHY_RFOVER,
1364 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0100);
1365 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1366 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xCFFF);
1368 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_EXTLNA) {
1369 if (phy->rev >= 7) {
1370 b43_phy_write(dev, B43_PHY_RFOVER,
1371 b43_phy_read(dev, B43_PHY_RFOVER)
1373 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1374 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1378 b43_radio_write16(dev, 0x7A, b43_radio_read16(dev, 0x7A)
1382 loop_i_max = (phy->radio_rev == 8) ? 15 : 9;
1383 for (i = 0; i < loop_i_max; i++) {
1384 for (j = 0; j < 16; j++) {
1385 b43_radio_write16(dev, 0x43, i);
1386 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1387 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1388 & 0xF0FF) | (j << 8));
1389 b43_phy_write(dev, B43_PHY_PGACTL,
1390 (b43_phy_read(dev, B43_PHY_PGACTL)
1391 & 0x0FFF) | 0xA000);
1392 b43_phy_write(dev, B43_PHY_PGACTL,
1393 b43_phy_read(dev, B43_PHY_PGACTL)
1396 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1401 loop1_outer_done = i;
1402 loop1_inner_done = j;
1404 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1405 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1408 for (j = j - 8; j < 16; j++) {
1409 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1410 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1411 & 0xF0FF) | (j << 8));
1412 b43_phy_write(dev, B43_PHY_PGACTL,
1413 (b43_phy_read(dev, B43_PHY_PGACTL)
1414 & 0x0FFF) | 0xA000);
1415 b43_phy_write(dev, B43_PHY_PGACTL,
1416 b43_phy_read(dev, B43_PHY_PGACTL)
1420 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1427 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1428 b43_phy_write(dev, B43_PHY_ANALOGOVER, backup_phy[4]);
1429 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, backup_phy[5]);
1431 b43_phy_write(dev, B43_PHY_BASE(0x5A), backup_phy[6]);
1432 b43_phy_write(dev, B43_PHY_BASE(0x59), backup_phy[7]);
1433 b43_phy_write(dev, B43_PHY_BASE(0x58), backup_phy[8]);
1434 b43_phy_write(dev, B43_PHY_BASE(0x0A), backup_phy[9]);
1435 b43_phy_write(dev, B43_PHY_BASE(0x03), backup_phy[10]);
1436 b43_phy_write(dev, B43_PHY_LO_MASK, backup_phy[11]);
1437 b43_phy_write(dev, B43_PHY_LO_CTL, backup_phy[12]);
1438 b43_phy_write(dev, B43_PHY_BASE(0x2B), backup_phy[13]);
1439 b43_phy_write(dev, B43_PHY_PGACTL, backup_phy[14]);
1441 b43_phy_set_baseband_attenuation(dev, backup_bband);
1443 b43_radio_write16(dev, 0x52, backup_radio[0]);
1444 b43_radio_write16(dev, 0x43, backup_radio[1]);
1445 b43_radio_write16(dev, 0x7A, backup_radio[2]);
1447 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2] | 0x0003);
1449 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2]);
1450 b43_phy_write(dev, B43_PHY_RFOVERVAL, backup_phy[3]);
1451 b43_phy_write(dev, B43_PHY_CRS0, backup_phy[0]);
1452 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, backup_phy[1]);
1455 ((loop1_inner_done * 6) - (loop1_outer_done * 4)) - 11;
1456 phy->trsw_rx_gain = trsw_rx * 2;
1459 static void b43_phy_initg(struct b43_wldev *dev)
1461 struct b43_phy *phy = &dev->phy;
1465 b43_phy_initb5(dev);
1467 b43_phy_initb6(dev);
1469 if (phy->rev >= 2 || phy->gmode)
1472 if (phy->rev >= 2) {
1473 b43_phy_write(dev, B43_PHY_ANALOGOVER, 0);
1474 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, 0);
1476 if (phy->rev == 2) {
1477 b43_phy_write(dev, B43_PHY_RFOVER, 0);
1478 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1481 b43_phy_write(dev, B43_PHY_RFOVER, 0x400);
1482 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1484 if (phy->gmode || phy->rev >= 2) {
1485 tmp = b43_phy_read(dev, B43_PHY_VERSION_OFDM);
1486 tmp &= B43_PHYVER_VERSION;
1487 if (tmp == 3 || tmp == 5) {
1488 b43_phy_write(dev, B43_PHY_OFDM(0xC2), 0x1816);
1489 b43_phy_write(dev, B43_PHY_OFDM(0xC3), 0x8006);
1492 b43_phy_write(dev, B43_PHY_OFDM(0xCC),
1493 (b43_phy_read(dev, B43_PHY_OFDM(0xCC))
1494 & 0x00FF) | 0x1F00);
1497 if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2)
1498 b43_phy_write(dev, B43_PHY_OFDM(0x7E), 0x78);
1499 if (phy->radio_rev == 8) {
1500 b43_phy_write(dev, B43_PHY_EXTG(0x01),
1501 b43_phy_read(dev, B43_PHY_EXTG(0x01))
1503 b43_phy_write(dev, B43_PHY_OFDM(0x3E),
1504 b43_phy_read(dev, B43_PHY_OFDM(0x3E))
1507 if (has_loopback_gain(phy))
1508 b43_calc_loopback_gain(dev);
1510 if (phy->radio_rev != 8) {
1511 if (phy->initval == 0xFFFF)
1512 phy->initval = b43_radio_init2050(dev);
1514 b43_radio_write16(dev, 0x0078, phy->initval);
1516 if (phy->lo_control->tx_bias == 0xFF) {
1517 b43_lo_g_measure(dev);
1519 if (has_tx_magnification(phy)) {
1520 b43_radio_write16(dev, 0x52,
1521 (b43_radio_read16(dev, 0x52) & 0xFF00)
1522 | phy->lo_control->tx_bias | phy->
1523 lo_control->tx_magn);
1525 b43_radio_write16(dev, 0x52,
1526 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1527 | phy->lo_control->tx_bias);
1529 if (phy->rev >= 6) {
1530 b43_phy_write(dev, B43_PHY_BASE(0x36),
1531 (b43_phy_read(dev, B43_PHY_BASE(0x36))
1532 & 0x0FFF) | (phy->lo_control->
1535 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)
1536 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x8075);
1538 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x807F);
1540 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x101);
1542 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x202);
1544 if (phy->gmode || phy->rev >= 2) {
1545 b43_lo_g_adjust(dev);
1546 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
1549 if (!(dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI)) {
1550 /* The specs state to update the NRSSI LT with
1551 * the value 0x7FFFFFFF here. I think that is some weird
1552 * compiler optimization in the original driver.
1553 * Essentially, what we do here is resetting all NRSSI LT
1554 * entries to -32 (see the limit_value() in nrssi_hw_update())
1556 b43_nrssi_hw_update(dev, 0xFFFF); //FIXME?
1557 b43_calc_nrssi_threshold(dev);
1558 } else if (phy->gmode || phy->rev >= 2) {
1559 if (phy->nrssi[0] == -1000) {
1560 B43_WARN_ON(phy->nrssi[1] != -1000);
1561 b43_calc_nrssi_slope(dev);
1563 b43_calc_nrssi_threshold(dev);
1565 if (phy->radio_rev == 8)
1566 b43_phy_write(dev, B43_PHY_EXTG(0x05), 0x3230);
1567 b43_phy_init_pctl(dev);
1568 /* FIXME: The spec says in the following if, the 0 should be replaced
1569 'if OFDM may not be used in the current locale'
1570 but OFDM is legal everywhere */
1571 if ((dev->dev->bus->chip_id == 0x4306
1572 && dev->dev->bus->chip_package == 2) || 0) {
1573 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
1575 b43_phy_write(dev, B43_PHY_OFDM(0xC3),
1576 b43_phy_read(dev, B43_PHY_OFDM(0xC3))
1581 /* Set the baseband attenuation value on chip. */
1582 void b43_phy_set_baseband_attenuation(struct b43_wldev *dev,
1583 u16 baseband_attenuation)
1585 struct b43_phy *phy = &dev->phy;
1587 if (phy->analog == 0) {
1588 b43_write16(dev, B43_MMIO_PHY0, (b43_read16(dev, B43_MMIO_PHY0)
1590 baseband_attenuation);
1591 } else if (phy->analog > 1) {
1592 b43_phy_write(dev, B43_PHY_DACCTL,
1593 (b43_phy_read(dev, B43_PHY_DACCTL)
1594 & 0xFFC3) | (baseband_attenuation << 2));
1596 b43_phy_write(dev, B43_PHY_DACCTL,
1597 (b43_phy_read(dev, B43_PHY_DACCTL)
1598 & 0xFF87) | (baseband_attenuation << 3));
1602 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1603 * This function converts a TSSI value to dBm in Q5.2
1605 static s8 b43_phy_estimate_power_out(struct b43_wldev *dev, s8 tssi)
1607 struct b43_phy *phy = &dev->phy;
1611 tmp = (phy->tgt_idle_tssi - phy->cur_idle_tssi + tssi);
1613 switch (phy->type) {
1616 tmp = limit_value(tmp, 0x00, 0xFF);
1617 dbm = phy->tssi2dbm[tmp];
1618 //TODO: There's a FIXME on the specs
1622 tmp = limit_value(tmp, 0x00, 0x3F);
1623 dbm = phy->tssi2dbm[tmp];
1632 void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
1633 int *_bbatt, int *_rfatt)
1635 int rfatt = *_rfatt;
1636 int bbatt = *_bbatt;
1637 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
1639 /* Get baseband and radio attenuation values into their permitted ranges.
1640 * Radio attenuation affects power level 4 times as much as baseband. */
1642 /* Range constants */
1643 const int rf_min = lo->rfatt_list.min_val;
1644 const int rf_max = lo->rfatt_list.max_val;
1645 const int bb_min = lo->bbatt_list.min_val;
1646 const int bb_max = lo->bbatt_list.max_val;
1649 if (rfatt > rf_max && bbatt > bb_max - 4)
1650 break; /* Can not get it into ranges */
1651 if (rfatt < rf_min && bbatt < bb_min + 4)
1652 break; /* Can not get it into ranges */
1653 if (bbatt > bb_max && rfatt > rf_max - 1)
1654 break; /* Can not get it into ranges */
1655 if (bbatt < bb_min && rfatt < rf_min + 1)
1656 break; /* Can not get it into ranges */
1658 if (bbatt > bb_max) {
1663 if (bbatt < bb_min) {
1668 if (rfatt > rf_max) {
1673 if (rfatt < rf_min) {
1681 *_rfatt = limit_value(rfatt, rf_min, rf_max);
1682 *_bbatt = limit_value(bbatt, bb_min, bb_max);
1685 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1686 void b43_phy_xmitpower(struct b43_wldev *dev)
1688 struct ssb_bus *bus = dev->dev->bus;
1689 struct b43_phy *phy = &dev->phy;
1691 if (phy->cur_idle_tssi == 0)
1693 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1694 (bus->boardinfo.type == SSB_BOARD_BU4306))
1696 #ifdef CONFIG_B43_DEBUG
1697 if (phy->manual_txpower_control)
1701 switch (phy->type) {
1702 case B43_PHYTYPE_A:{
1704 //TODO: Nothing for A PHYs yet :-/
1709 case B43_PHYTYPE_G:{
1714 int desired_pwr, estimated_pwr, pwr_adjust;
1715 int rfatt_delta, bbatt_delta;
1718 unsigned long phylock_flags;
1720 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x0058);
1721 v0 = (s8) (tmp & 0x00FF);
1722 v1 = (s8) ((tmp & 0xFF00) >> 8);
1723 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x005A);
1724 v2 = (s8) (tmp & 0x00FF);
1725 v3 = (s8) ((tmp & 0xFF00) >> 8);
1728 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
1731 b43_shm_read16(dev, B43_SHM_SHARED, 0x0070);
1732 v0 = (s8) (tmp & 0x00FF);
1733 v1 = (s8) ((tmp & 0xFF00) >> 8);
1735 b43_shm_read16(dev, B43_SHM_SHARED, 0x0072);
1736 v2 = (s8) (tmp & 0x00FF);
1737 v3 = (s8) ((tmp & 0xFF00) >> 8);
1738 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
1741 v0 = (v0 + 0x20) & 0x3F;
1742 v1 = (v1 + 0x20) & 0x3F;
1743 v2 = (v2 + 0x20) & 0x3F;
1744 v3 = (v3 + 0x20) & 0x3F;
1747 b43_shm_clear_tssi(dev);
1749 average = (v0 + v1 + v2 + v3 + 2) / 4;
1752 && (b43_shm_read16(dev, B43_SHM_SHARED, 0x005E) &
1757 b43_phy_estimate_power_out(dev, average);
1759 max_pwr = dev->dev->bus->sprom.maxpwr_bg;
1760 if ((dev->dev->bus->sprom.boardflags_lo
1761 & B43_BFL_PACTRL) && (phy->type == B43_PHYTYPE_G))
1763 if (unlikely(max_pwr <= 0)) {
1765 "Invalid max-TX-power value in SPROM.\n");
1766 max_pwr = 60; /* fake it */
1767 dev->dev->bus->sprom.maxpwr_bg = max_pwr;
1771 max_pwr = min(REG - dev->dev->bus->sprom.antennagain_bgphy - 0x6, max_pwr)
1772 where REG is the max power as per the regulatory domain
1775 /* Get desired power (in Q5.2) */
1776 desired_pwr = INT_TO_Q52(phy->power_level);
1777 /* And limit it. max_pwr already is Q5.2 */
1778 desired_pwr = limit_value(desired_pwr, 0, max_pwr);
1779 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
1781 "Current TX power output: " Q52_FMT
1782 " dBm, " "Desired TX power output: "
1783 Q52_FMT " dBm\n", Q52_ARG(estimated_pwr),
1784 Q52_ARG(desired_pwr));
1787 /* Calculate the adjustment delta. */
1788 pwr_adjust = desired_pwr - estimated_pwr;
1790 /* RF attenuation delta. */
1791 rfatt_delta = ((pwr_adjust + 7) / 8);
1792 /* Lower attenuation => Bigger power output. Negate it. */
1793 rfatt_delta = -rfatt_delta;
1795 /* Baseband attenuation delta. */
1796 bbatt_delta = pwr_adjust / 2;
1797 /* Lower attenuation => Bigger power output. Negate it. */
1798 bbatt_delta = -bbatt_delta;
1799 /* RF att affects power level 4 times as much as
1800 * Baseband attennuation. Subtract it. */
1801 bbatt_delta -= 4 * rfatt_delta;
1803 /* So do we finally need to adjust something? */
1804 if ((rfatt_delta == 0) && (bbatt_delta == 0)) {
1805 b43_lo_g_ctl_mark_cur_used(dev);
1809 /* Calculate the new attenuation values. */
1810 bbatt = phy->bbatt.att;
1811 bbatt += bbatt_delta;
1812 rfatt = phy->rfatt.att;
1813 rfatt += rfatt_delta;
1815 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
1816 tx_control = phy->tx_control;
1817 if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 2)) {
1819 if (tx_control == 0) {
1825 } else if (dev->dev->bus->sprom.
1828 bbatt += 4 * (rfatt - 2);
1831 } else if (rfatt > 4 && tx_control) {
1842 /* Save the control values */
1843 phy->tx_control = tx_control;
1844 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
1845 phy->rfatt.att = rfatt;
1846 phy->bbatt.att = bbatt;
1848 /* Adjust the hardware */
1849 b43_phy_lock(dev, phylock_flags);
1850 b43_radio_lock(dev);
1851 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt,
1853 b43_lo_g_ctl_mark_cur_used(dev);
1854 b43_radio_unlock(dev);
1855 b43_phy_unlock(dev, phylock_flags);
1863 static inline s32 b43_tssi2dbm_ad(s32 num, s32 den)
1868 return (num + den / 2) / den;
1872 s8 b43_tssi2dbm_entry(s8 entry[], u8 index, s16 pab0, s16 pab1, s16 pab2)
1874 s32 m1, m2, f = 256, q, delta;
1877 m1 = b43_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
1878 m2 = max(b43_tssi2dbm_ad(32768 + index * pab2, 256), 1);
1882 q = b43_tssi2dbm_ad(f * 4096 -
1883 b43_tssi2dbm_ad(m2 * f, 16) * f, 2048);
1887 } while (delta >= 2);
1888 entry[index] = limit_value(b43_tssi2dbm_ad(m1 * f, 8192), -127, 128);
1892 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
1893 int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev)
1895 struct b43_phy *phy = &dev->phy;
1896 s16 pab0, pab1, pab2;
1900 if (phy->type == B43_PHYTYPE_A) {
1901 pab0 = (s16) (dev->dev->bus->sprom.pa1b0);
1902 pab1 = (s16) (dev->dev->bus->sprom.pa1b1);
1903 pab2 = (s16) (dev->dev->bus->sprom.pa1b2);
1905 pab0 = (s16) (dev->dev->bus->sprom.pa0b0);
1906 pab1 = (s16) (dev->dev->bus->sprom.pa0b1);
1907 pab2 = (s16) (dev->dev->bus->sprom.pa0b2);
1910 if ((dev->dev->bus->chip_id == 0x4301) && (phy->radio_ver != 0x2050)) {
1911 phy->tgt_idle_tssi = 0x34;
1912 phy->tssi2dbm = b43_tssi2dbm_b_table;
1916 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
1917 pab0 != -1 && pab1 != -1 && pab2 != -1) {
1918 /* The pabX values are set in SPROM. Use them. */
1919 if (phy->type == B43_PHYTYPE_A) {
1920 if ((s8) dev->dev->bus->sprom.itssi_a != 0 &&
1921 (s8) dev->dev->bus->sprom.itssi_a != -1)
1922 phy->tgt_idle_tssi =
1923 (s8) (dev->dev->bus->sprom.itssi_a);
1925 phy->tgt_idle_tssi = 62;
1927 if ((s8) dev->dev->bus->sprom.itssi_bg != 0 &&
1928 (s8) dev->dev->bus->sprom.itssi_bg != -1)
1929 phy->tgt_idle_tssi =
1930 (s8) (dev->dev->bus->sprom.itssi_bg);
1932 phy->tgt_idle_tssi = 62;
1934 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
1935 if (dyn_tssi2dbm == NULL) {
1936 b43err(dev->wl, "Could not allocate memory "
1937 "for tssi2dbm table\n");
1940 for (idx = 0; idx < 64; idx++)
1941 if (b43_tssi2dbm_entry
1942 (dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
1943 phy->tssi2dbm = NULL;
1944 b43err(dev->wl, "Could not generate "
1945 "tssi2dBm table\n");
1946 kfree(dyn_tssi2dbm);
1949 phy->tssi2dbm = dyn_tssi2dbm;
1950 phy->dyn_tssi_tbl = 1;
1952 /* pabX values not set in SPROM. */
1953 switch (phy->type) {
1955 /* APHY needs a generated table. */
1956 phy->tssi2dbm = NULL;
1957 b43err(dev->wl, "Could not generate tssi2dBm "
1958 "table (wrong SPROM info)!\n");
1961 phy->tgt_idle_tssi = 0x34;
1962 phy->tssi2dbm = b43_tssi2dbm_b_table;
1965 phy->tgt_idle_tssi = 0x34;
1966 phy->tssi2dbm = b43_tssi2dbm_g_table;
1974 int b43_phy_init(struct b43_wldev *dev)
1976 struct b43_phy *phy = &dev->phy;
1979 switch (phy->type) {
1981 if (phy->rev == 2 || phy->rev == 3) {
1989 b43_phy_initb2(dev);
1993 b43_phy_initb4(dev);
1997 b43_phy_initb5(dev);
2001 b43_phy_initb6(dev);
2012 b43err(dev->wl, "Unknown PHYTYPE found\n");
2017 void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2019 struct b43_phy *phy = &dev->phy;
2024 if (antenna == B43_ANTENNA_AUTO0 || antenna == B43_ANTENNA_AUTO1)
2027 hf = b43_hf_read(dev);
2028 hf &= ~B43_HF_ANTDIVHELP;
2029 b43_hf_write(dev, hf);
2031 switch (phy->type) {
2034 tmp = b43_phy_read(dev, B43_PHY_BBANDCFG);
2035 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2036 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2037 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2038 b43_phy_write(dev, B43_PHY_BBANDCFG, tmp);
2041 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2042 if (antenna == B43_ANTENNA_AUTO0)
2043 tmp &= ~B43_PHY_ANTDWELL_AUTODIV1;
2045 tmp |= B43_PHY_ANTDWELL_AUTODIV1;
2046 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2048 if (phy->type == B43_PHYTYPE_G) {
2049 tmp = b43_phy_read(dev, B43_PHY_ANTWRSETT);
2051 tmp |= B43_PHY_ANTWRSETT_ARXDIV;
2053 tmp &= ~B43_PHY_ANTWRSETT_ARXDIV;
2054 b43_phy_write(dev, B43_PHY_ANTWRSETT, tmp);
2055 if (phy->rev >= 2) {
2056 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2057 tmp |= B43_PHY_OFDM61_10;
2058 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2061 b43_phy_read(dev, B43_PHY_DIVSRCHGAINBACK);
2062 tmp = (tmp & 0xFF00) | 0x15;
2063 b43_phy_write(dev, B43_PHY_DIVSRCHGAINBACK,
2066 if (phy->rev == 2) {
2067 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2072 B43_PHY_ADIVRELATED);
2073 tmp = (tmp & 0xFF00) | 8;
2074 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2079 b43_phy_write(dev, B43_PHY_OFDM9B, 0xDC);
2082 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2083 tmp = (tmp & 0xFF00) | 0x24;
2084 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2086 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2088 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2089 if (phy->analog == 3) {
2090 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2092 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2095 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2099 B43_PHY_ADIVRELATED);
2100 tmp = (tmp & 0xFF00) | 8;
2101 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2108 tmp = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
2109 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2110 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2111 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2112 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, tmp);
2118 hf |= B43_HF_ANTDIVHELP;
2119 b43_hf_write(dev, hf);
2122 /* Get the freq, as it has to be written to the device. */
2123 static inline u16 channel2freq_bg(u8 channel)
2125 B43_WARN_ON(!(channel >= 1 && channel <= 14));
2127 return b43_radio_channel_codes_bg[channel - 1];
2130 /* Get the freq, as it has to be written to the device. */
2131 static inline u16 channel2freq_a(u8 channel)
2133 B43_WARN_ON(channel > 200);
2135 return (5000 + 5 * channel);
2138 void b43_radio_lock(struct b43_wldev *dev)
2142 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2143 macctl |= B43_MACCTL_RADIOLOCK;
2144 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2145 /* Commit the write and wait for the device
2146 * to exit any radio register access. */
2147 b43_read32(dev, B43_MMIO_MACCTL);
2151 void b43_radio_unlock(struct b43_wldev *dev)
2155 /* Commit any write */
2156 b43_read16(dev, B43_MMIO_PHY_VER);
2158 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2159 macctl &= ~B43_MACCTL_RADIOLOCK;
2160 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2163 u16 b43_radio_read16(struct b43_wldev *dev, u16 offset)
2165 struct b43_phy *phy = &dev->phy;
2167 switch (phy->type) {
2172 if (phy->radio_ver == 0x2053) {
2175 else if (offset < 0x80)
2177 } else if (phy->radio_ver == 0x2050) {
2187 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2188 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
2191 void b43_radio_write16(struct b43_wldev *dev, u16 offset, u16 val)
2193 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2195 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, val);
2198 static void b43_set_all_gains(struct b43_wldev *dev,
2199 s16 first, s16 second, s16 third)
2201 struct b43_phy *phy = &dev->phy;
2203 u16 start = 0x08, end = 0x18;
2207 if (phy->rev <= 1) {
2212 table = B43_OFDMTAB_GAINX;
2214 table = B43_OFDMTAB_GAINX_R1;
2215 for (i = 0; i < 4; i++)
2216 b43_ofdmtab_write16(dev, table, i, first);
2218 for (i = start; i < end; i++)
2219 b43_ofdmtab_write16(dev, table, i, second);
2222 tmp = ((u16) third << 14) | ((u16) third << 6);
2223 b43_phy_write(dev, 0x04A0,
2224 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | tmp);
2225 b43_phy_write(dev, 0x04A1,
2226 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | tmp);
2227 b43_phy_write(dev, 0x04A2,
2228 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | tmp);
2230 b43_dummy_transmission(dev);
2233 static void b43_set_original_gains(struct b43_wldev *dev)
2235 struct b43_phy *phy = &dev->phy;
2238 u16 start = 0x0008, end = 0x0018;
2240 if (phy->rev <= 1) {
2245 table = B43_OFDMTAB_GAINX;
2247 table = B43_OFDMTAB_GAINX_R1;
2248 for (i = 0; i < 4; i++) {
2250 tmp |= (i & 0x0001) << 1;
2251 tmp |= (i & 0x0002) >> 1;
2253 b43_ofdmtab_write16(dev, table, i, tmp);
2256 for (i = start; i < end; i++)
2257 b43_ofdmtab_write16(dev, table, i, i - start);
2259 b43_phy_write(dev, 0x04A0,
2260 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | 0x4040);
2261 b43_phy_write(dev, 0x04A1,
2262 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | 0x4040);
2263 b43_phy_write(dev, 0x04A2,
2264 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | 0x4000);
2265 b43_dummy_transmission(dev);
2268 /* Synthetic PU workaround */
2269 static void b43_synth_pu_workaround(struct b43_wldev *dev, u8 channel)
2271 struct b43_phy *phy = &dev->phy;
2275 if (phy->radio_ver != 0x2050 || phy->radio_rev >= 6) {
2276 /* We do not need the workaround. */
2280 if (channel <= 10) {
2281 b43_write16(dev, B43_MMIO_CHANNEL,
2282 channel2freq_bg(channel + 4));
2284 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(1));
2287 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
2290 u8 b43_radio_aci_detect(struct b43_wldev *dev, u8 channel)
2292 struct b43_phy *phy = &dev->phy;
2294 u16 saved, rssi, temp;
2297 saved = b43_phy_read(dev, 0x0403);
2298 b43_radio_selectchannel(dev, channel, 0);
2299 b43_phy_write(dev, 0x0403, (saved & 0xFFF8) | 5);
2300 if (phy->aci_hw_rssi)
2301 rssi = b43_phy_read(dev, 0x048A) & 0x3F;
2303 rssi = saved & 0x3F;
2304 /* clamp temp to signed 5bit */
2307 for (i = 0; i < 100; i++) {
2308 temp = (b43_phy_read(dev, 0x047F) >> 8) & 0x3F;
2316 b43_phy_write(dev, 0x0403, saved);
2321 u8 b43_radio_aci_scan(struct b43_wldev * dev)
2323 struct b43_phy *phy = &dev->phy;
2325 unsigned int channel = phy->channel;
2326 unsigned int i, j, start, end;
2327 unsigned long phylock_flags;
2329 if (!((phy->type == B43_PHYTYPE_G) && (phy->rev > 0)))
2332 b43_phy_lock(dev, phylock_flags);
2333 b43_radio_lock(dev);
2334 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2335 b43_phy_write(dev, B43_PHY_G_CRS,
2336 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2337 b43_set_all_gains(dev, 3, 8, 1);
2339 start = (channel - 5 > 0) ? channel - 5 : 1;
2340 end = (channel + 5 < 14) ? channel + 5 : 13;
2342 for (i = start; i <= end; i++) {
2343 if (abs(channel - i) > 2)
2344 ret[i - 1] = b43_radio_aci_detect(dev, i);
2346 b43_radio_selectchannel(dev, channel, 0);
2347 b43_phy_write(dev, 0x0802,
2348 (b43_phy_read(dev, 0x0802) & 0xFFFC) | 0x0003);
2349 b43_phy_write(dev, 0x0403, b43_phy_read(dev, 0x0403) & 0xFFF8);
2350 b43_phy_write(dev, B43_PHY_G_CRS,
2351 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2352 b43_set_original_gains(dev);
2353 for (i = 0; i < 13; i++) {
2356 end = (i + 5 < 13) ? i + 5 : 13;
2357 for (j = i; j < end; j++)
2360 b43_radio_unlock(dev);
2361 b43_phy_unlock(dev, phylock_flags);
2363 return ret[channel - 1];
2366 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2367 void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val)
2369 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2371 b43_phy_write(dev, B43_PHY_NRSSILT_DATA, (u16) val);
2374 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2375 s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset)
2379 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2380 val = b43_phy_read(dev, B43_PHY_NRSSILT_DATA);
2385 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2386 void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val)
2391 for (i = 0; i < 64; i++) {
2392 tmp = b43_nrssi_hw_read(dev, i);
2394 tmp = limit_value(tmp, -32, 31);
2395 b43_nrssi_hw_write(dev, i, tmp);
2399 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2400 void b43_nrssi_mem_update(struct b43_wldev *dev)
2402 struct b43_phy *phy = &dev->phy;
2406 delta = 0x1F - phy->nrssi[0];
2407 for (i = 0; i < 64; i++) {
2408 tmp = (i - delta) * phy->nrssislope;
2411 tmp = limit_value(tmp, 0, 0x3F);
2412 phy->nrssi_lt[i] = tmp;
2416 static void b43_calc_nrssi_offset(struct b43_wldev *dev)
2418 struct b43_phy *phy = &dev->phy;
2419 u16 backup[20] = { 0 };
2424 backup[0] = b43_phy_read(dev, 0x0001);
2425 backup[1] = b43_phy_read(dev, 0x0811);
2426 backup[2] = b43_phy_read(dev, 0x0812);
2427 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2428 backup[3] = b43_phy_read(dev, 0x0814);
2429 backup[4] = b43_phy_read(dev, 0x0815);
2431 backup[5] = b43_phy_read(dev, 0x005A);
2432 backup[6] = b43_phy_read(dev, 0x0059);
2433 backup[7] = b43_phy_read(dev, 0x0058);
2434 backup[8] = b43_phy_read(dev, 0x000A);
2435 backup[9] = b43_phy_read(dev, 0x0003);
2436 backup[10] = b43_radio_read16(dev, 0x007A);
2437 backup[11] = b43_radio_read16(dev, 0x0043);
2439 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) & 0x7FFF);
2440 b43_phy_write(dev, 0x0001,
2441 (b43_phy_read(dev, 0x0001) & 0x3FFF) | 0x4000);
2442 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2443 b43_phy_write(dev, 0x0812,
2444 (b43_phy_read(dev, 0x0812) & 0xFFF3) | 0x0004);
2445 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & ~(0x1 | 0x2));
2446 if (phy->rev >= 6) {
2447 backup[12] = b43_phy_read(dev, 0x002E);
2448 backup[13] = b43_phy_read(dev, 0x002F);
2449 backup[14] = b43_phy_read(dev, 0x080F);
2450 backup[15] = b43_phy_read(dev, 0x0810);
2451 backup[16] = b43_phy_read(dev, 0x0801);
2452 backup[17] = b43_phy_read(dev, 0x0060);
2453 backup[18] = b43_phy_read(dev, 0x0014);
2454 backup[19] = b43_phy_read(dev, 0x0478);
2456 b43_phy_write(dev, 0x002E, 0);
2457 b43_phy_write(dev, 0x002F, 0);
2458 b43_phy_write(dev, 0x080F, 0);
2459 b43_phy_write(dev, 0x0810, 0);
2460 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478) | 0x0100);
2461 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801) | 0x0040);
2462 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) | 0x0040);
2463 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014) | 0x0200);
2465 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0070);
2466 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0080);
2469 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2473 for (i = 7; i >= 4; i--) {
2474 b43_radio_write16(dev, 0x007B, i);
2477 (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2480 if (v47F < 31 && saved == 0xFFFF)
2483 if (saved == 0xFFFF)
2486 b43_radio_write16(dev, 0x007A,
2487 b43_radio_read16(dev, 0x007A) & 0x007F);
2488 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2489 b43_phy_write(dev, 0x0814,
2490 b43_phy_read(dev, 0x0814) | 0x0001);
2491 b43_phy_write(dev, 0x0815,
2492 b43_phy_read(dev, 0x0815) & 0xFFFE);
2494 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2495 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x000C);
2496 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x0030);
2497 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x0030);
2498 b43_phy_write(dev, 0x005A, 0x0480);
2499 b43_phy_write(dev, 0x0059, 0x0810);
2500 b43_phy_write(dev, 0x0058, 0x000D);
2501 if (phy->rev == 0) {
2502 b43_phy_write(dev, 0x0003, 0x0122);
2504 b43_phy_write(dev, 0x000A, b43_phy_read(dev, 0x000A)
2507 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2508 b43_phy_write(dev, 0x0814,
2509 b43_phy_read(dev, 0x0814) | 0x0004);
2510 b43_phy_write(dev, 0x0815,
2511 b43_phy_read(dev, 0x0815) & 0xFFFB);
2513 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003) & 0xFF9F)
2515 b43_radio_write16(dev, 0x007A,
2516 b43_radio_read16(dev, 0x007A) | 0x000F);
2517 b43_set_all_gains(dev, 3, 0, 1);
2518 b43_radio_write16(dev, 0x0043, (b43_radio_read16(dev, 0x0043)
2519 & 0x00F0) | 0x000F);
2521 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2525 for (i = 0; i < 4; i++) {
2526 b43_radio_write16(dev, 0x007B, i);
2529 (s16) ((b43_phy_read(dev, 0x047F) >> 8) &
2533 if (v47F > -31 && saved == 0xFFFF)
2536 if (saved == 0xFFFF)
2541 b43_radio_write16(dev, 0x007B, saved);
2543 if (phy->rev >= 6) {
2544 b43_phy_write(dev, 0x002E, backup[12]);
2545 b43_phy_write(dev, 0x002F, backup[13]);
2546 b43_phy_write(dev, 0x080F, backup[14]);
2547 b43_phy_write(dev, 0x0810, backup[15]);
2549 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2550 b43_phy_write(dev, 0x0814, backup[3]);
2551 b43_phy_write(dev, 0x0815, backup[4]);
2553 b43_phy_write(dev, 0x005A, backup[5]);
2554 b43_phy_write(dev, 0x0059, backup[6]);
2555 b43_phy_write(dev, 0x0058, backup[7]);
2556 b43_phy_write(dev, 0x000A, backup[8]);
2557 b43_phy_write(dev, 0x0003, backup[9]);
2558 b43_radio_write16(dev, 0x0043, backup[11]);
2559 b43_radio_write16(dev, 0x007A, backup[10]);
2560 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x1 | 0x2);
2561 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) | 0x8000);
2562 b43_set_original_gains(dev);
2563 if (phy->rev >= 6) {
2564 b43_phy_write(dev, 0x0801, backup[16]);
2565 b43_phy_write(dev, 0x0060, backup[17]);
2566 b43_phy_write(dev, 0x0014, backup[18]);
2567 b43_phy_write(dev, 0x0478, backup[19]);
2569 b43_phy_write(dev, 0x0001, backup[0]);
2570 b43_phy_write(dev, 0x0812, backup[2]);
2571 b43_phy_write(dev, 0x0811, backup[1]);
2574 void b43_calc_nrssi_slope(struct b43_wldev *dev)
2576 struct b43_phy *phy = &dev->phy;
2577 u16 backup[18] = { 0 };
2581 switch (phy->type) {
2583 backup[0] = b43_radio_read16(dev, 0x007A);
2584 backup[1] = b43_radio_read16(dev, 0x0052);
2585 backup[2] = b43_radio_read16(dev, 0x0043);
2586 backup[3] = b43_phy_read(dev, 0x0030);
2587 backup[4] = b43_phy_read(dev, 0x0026);
2588 backup[5] = b43_phy_read(dev, 0x0015);
2589 backup[6] = b43_phy_read(dev, 0x002A);
2590 backup[7] = b43_phy_read(dev, 0x0020);
2591 backup[8] = b43_phy_read(dev, 0x005A);
2592 backup[9] = b43_phy_read(dev, 0x0059);
2593 backup[10] = b43_phy_read(dev, 0x0058);
2594 backup[11] = b43_read16(dev, 0x03E2);
2595 backup[12] = b43_read16(dev, 0x03E6);
2596 backup[13] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2598 tmp = b43_radio_read16(dev, 0x007A);
2599 tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
2600 b43_radio_write16(dev, 0x007A, tmp);
2601 b43_phy_write(dev, 0x0030, 0x00FF);
2602 b43_write16(dev, 0x03EC, 0x7F7F);
2603 b43_phy_write(dev, 0x0026, 0x0000);
2604 b43_phy_write(dev, 0x0015, b43_phy_read(dev, 0x0015) | 0x0020);
2605 b43_phy_write(dev, 0x002A, 0x08A3);
2606 b43_radio_write16(dev, 0x007A,
2607 b43_radio_read16(dev, 0x007A) | 0x0080);
2609 nrssi0 = (s16) b43_phy_read(dev, 0x0027);
2610 b43_radio_write16(dev, 0x007A,
2611 b43_radio_read16(dev, 0x007A) & 0x007F);
2612 if (phy->rev >= 2) {
2613 b43_write16(dev, 0x03E6, 0x0040);
2614 } else if (phy->rev == 0) {
2615 b43_write16(dev, 0x03E6, 0x0122);
2617 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2619 B43_MMIO_CHANNEL_EXT) & 0x2000);
2621 b43_phy_write(dev, 0x0020, 0x3F3F);
2622 b43_phy_write(dev, 0x0015, 0xF330);
2623 b43_radio_write16(dev, 0x005A, 0x0060);
2624 b43_radio_write16(dev, 0x0043,
2625 b43_radio_read16(dev, 0x0043) & 0x00F0);
2626 b43_phy_write(dev, 0x005A, 0x0480);
2627 b43_phy_write(dev, 0x0059, 0x0810);
2628 b43_phy_write(dev, 0x0058, 0x000D);
2631 nrssi1 = (s16) b43_phy_read(dev, 0x0027);
2632 b43_phy_write(dev, 0x0030, backup[3]);
2633 b43_radio_write16(dev, 0x007A, backup[0]);
2634 b43_write16(dev, 0x03E2, backup[11]);
2635 b43_phy_write(dev, 0x0026, backup[4]);
2636 b43_phy_write(dev, 0x0015, backup[5]);
2637 b43_phy_write(dev, 0x002A, backup[6]);
2638 b43_synth_pu_workaround(dev, phy->channel);
2640 b43_write16(dev, 0x03F4, backup[13]);
2642 b43_phy_write(dev, 0x0020, backup[7]);
2643 b43_phy_write(dev, 0x005A, backup[8]);
2644 b43_phy_write(dev, 0x0059, backup[9]);
2645 b43_phy_write(dev, 0x0058, backup[10]);
2646 b43_radio_write16(dev, 0x0052, backup[1]);
2647 b43_radio_write16(dev, 0x0043, backup[2]);
2649 if (nrssi0 == nrssi1)
2650 phy->nrssislope = 0x00010000;
2652 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2655 phy->nrssi[0] = nrssi0;
2656 phy->nrssi[1] = nrssi1;
2660 if (phy->radio_rev >= 9)
2662 if (phy->radio_rev == 8)
2663 b43_calc_nrssi_offset(dev);
2665 b43_phy_write(dev, B43_PHY_G_CRS,
2666 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2667 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2668 backup[7] = b43_read16(dev, 0x03E2);
2669 b43_write16(dev, 0x03E2, b43_read16(dev, 0x03E2) | 0x8000);
2670 backup[0] = b43_radio_read16(dev, 0x007A);
2671 backup[1] = b43_radio_read16(dev, 0x0052);
2672 backup[2] = b43_radio_read16(dev, 0x0043);
2673 backup[3] = b43_phy_read(dev, 0x0015);
2674 backup[4] = b43_phy_read(dev, 0x005A);
2675 backup[5] = b43_phy_read(dev, 0x0059);
2676 backup[6] = b43_phy_read(dev, 0x0058);
2677 backup[8] = b43_read16(dev, 0x03E6);
2678 backup[9] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2679 if (phy->rev >= 3) {
2680 backup[10] = b43_phy_read(dev, 0x002E);
2681 backup[11] = b43_phy_read(dev, 0x002F);
2682 backup[12] = b43_phy_read(dev, 0x080F);
2683 backup[13] = b43_phy_read(dev, B43_PHY_G_LO_CONTROL);
2684 backup[14] = b43_phy_read(dev, 0x0801);
2685 backup[15] = b43_phy_read(dev, 0x0060);
2686 backup[16] = b43_phy_read(dev, 0x0014);
2687 backup[17] = b43_phy_read(dev, 0x0478);
2688 b43_phy_write(dev, 0x002E, 0);
2689 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, 0);
2694 b43_phy_write(dev, 0x0478,
2695 b43_phy_read(dev, 0x0478)
2697 b43_phy_write(dev, 0x0801,
2698 b43_phy_read(dev, 0x0801)
2703 b43_phy_write(dev, 0x0801,
2704 b43_phy_read(dev, 0x0801)
2708 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060)
2710 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014)
2713 b43_radio_write16(dev, 0x007A,
2714 b43_radio_read16(dev, 0x007A) | 0x0070);
2715 b43_set_all_gains(dev, 0, 8, 0);
2716 b43_radio_write16(dev, 0x007A,
2717 b43_radio_read16(dev, 0x007A) & 0x00F7);
2718 if (phy->rev >= 2) {
2719 b43_phy_write(dev, 0x0811,
2720 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
2722 b43_phy_write(dev, 0x0812,
2723 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
2726 b43_radio_write16(dev, 0x007A,
2727 b43_radio_read16(dev, 0x007A) | 0x0080);
2730 nrssi0 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2731 if (nrssi0 >= 0x0020)
2734 b43_radio_write16(dev, 0x007A,
2735 b43_radio_read16(dev, 0x007A) & 0x007F);
2736 if (phy->rev >= 2) {
2737 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003)
2738 & 0xFF9F) | 0x0040);
2741 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2742 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
2744 b43_radio_write16(dev, 0x007A,
2745 b43_radio_read16(dev, 0x007A) | 0x000F);
2746 b43_phy_write(dev, 0x0015, 0xF330);
2747 if (phy->rev >= 2) {
2748 b43_phy_write(dev, 0x0812,
2749 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
2751 b43_phy_write(dev, 0x0811,
2752 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
2756 b43_set_all_gains(dev, 3, 0, 1);
2757 if (phy->radio_rev == 8) {
2758 b43_radio_write16(dev, 0x0043, 0x001F);
2760 tmp = b43_radio_read16(dev, 0x0052) & 0xFF0F;
2761 b43_radio_write16(dev, 0x0052, tmp | 0x0060);
2762 tmp = b43_radio_read16(dev, 0x0043) & 0xFFF0;
2763 b43_radio_write16(dev, 0x0043, tmp | 0x0009);
2765 b43_phy_write(dev, 0x005A, 0x0480);
2766 b43_phy_write(dev, 0x0059, 0x0810);
2767 b43_phy_write(dev, 0x0058, 0x000D);
2769 nrssi1 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2770 if (nrssi1 >= 0x0020)
2772 if (nrssi0 == nrssi1)
2773 phy->nrssislope = 0x00010000;
2775 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2777 phy->nrssi[0] = nrssi1;
2778 phy->nrssi[1] = nrssi0;
2780 if (phy->rev >= 3) {
2781 b43_phy_write(dev, 0x002E, backup[10]);
2782 b43_phy_write(dev, 0x002F, backup[11]);
2783 b43_phy_write(dev, 0x080F, backup[12]);
2784 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, backup[13]);
2786 if (phy->rev >= 2) {
2787 b43_phy_write(dev, 0x0812,
2788 b43_phy_read(dev, 0x0812) & 0xFFCF);
2789 b43_phy_write(dev, 0x0811,
2790 b43_phy_read(dev, 0x0811) & 0xFFCF);
2793 b43_radio_write16(dev, 0x007A, backup[0]);
2794 b43_radio_write16(dev, 0x0052, backup[1]);
2795 b43_radio_write16(dev, 0x0043, backup[2]);
2796 b43_write16(dev, 0x03E2, backup[7]);
2797 b43_write16(dev, 0x03E6, backup[8]);
2798 b43_write16(dev, B43_MMIO_CHANNEL_EXT, backup[9]);
2799 b43_phy_write(dev, 0x0015, backup[3]);
2800 b43_phy_write(dev, 0x005A, backup[4]);
2801 b43_phy_write(dev, 0x0059, backup[5]);
2802 b43_phy_write(dev, 0x0058, backup[6]);
2803 b43_synth_pu_workaround(dev, phy->channel);
2804 b43_phy_write(dev, 0x0802,
2805 b43_phy_read(dev, 0x0802) | (0x0001 | 0x0002));
2806 b43_set_original_gains(dev);
2807 b43_phy_write(dev, B43_PHY_G_CRS,
2808 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2809 if (phy->rev >= 3) {
2810 b43_phy_write(dev, 0x0801, backup[14]);
2811 b43_phy_write(dev, 0x0060, backup[15]);
2812 b43_phy_write(dev, 0x0014, backup[16]);
2813 b43_phy_write(dev, 0x0478, backup[17]);
2815 b43_nrssi_mem_update(dev);
2816 b43_calc_nrssi_threshold(dev);
2823 void b43_calc_nrssi_threshold(struct b43_wldev *dev)
2825 struct b43_phy *phy = &dev->phy;
2831 switch (phy->type) {
2832 case B43_PHYTYPE_B:{
2833 if (phy->radio_ver != 0x2050)
2836 (dev->dev->bus->sprom.
2837 boardflags_lo & B43_BFL_RSSI))
2840 if (phy->radio_rev >= 6) {
2842 (phy->nrssi[1] - phy->nrssi[0]) * 32;
2843 threshold += 20 * (phy->nrssi[0] + 1);
2846 threshold = phy->nrssi[1] - 5;
2848 threshold = limit_value(threshold, 0, 0x3E);
2849 b43_phy_read(dev, 0x0020); /* dummy read */
2850 b43_phy_write(dev, 0x0020,
2851 (((u16) threshold) << 8) | 0x001C);
2853 if (phy->radio_rev >= 6) {
2854 b43_phy_write(dev, 0x0087, 0x0E0D);
2855 b43_phy_write(dev, 0x0086, 0x0C0B);
2856 b43_phy_write(dev, 0x0085, 0x0A09);
2857 b43_phy_write(dev, 0x0084, 0x0808);
2858 b43_phy_write(dev, 0x0083, 0x0808);
2859 b43_phy_write(dev, 0x0082, 0x0604);
2860 b43_phy_write(dev, 0x0081, 0x0302);
2861 b43_phy_write(dev, 0x0080, 0x0100);
2867 !(dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI)) {
2868 tmp16 = b43_nrssi_hw_read(dev, 0x20);
2872 b43_phy_write(dev, 0x048A,
2873 (b43_phy_read(dev, 0x048A)
2874 & 0xF000) | 0x09EB);
2876 b43_phy_write(dev, 0x048A,
2877 (b43_phy_read(dev, 0x048A)
2878 & 0xF000) | 0x0AED);
2881 if (phy->interfmode == B43_INTERFMODE_NONWLAN) {
2884 } else if (!phy->aci_wlan_automatic && phy->aci_enable) {
2892 a = a * (phy->nrssi[1] - phy->nrssi[0]);
2893 a += (phy->nrssi[0] << 6);
2899 a = limit_value(a, -31, 31);
2901 b = b * (phy->nrssi[1] - phy->nrssi[0]);
2902 b += (phy->nrssi[0] << 6);
2908 b = limit_value(b, -31, 31);
2910 tmp_u16 = b43_phy_read(dev, 0x048A) & 0xF000;
2911 tmp_u16 |= ((u32) b & 0x0000003F);
2912 tmp_u16 |= (((u32) a & 0x0000003F) << 6);
2913 b43_phy_write(dev, 0x048A, tmp_u16);
2921 /* Stack implementation to save/restore values from the
2922 * interference mitigation code.
2923 * It is save to restore values in random order.
2925 static void _stack_save(u32 * _stackptr, size_t * stackidx,
2926 u8 id, u16 offset, u16 value)
2928 u32 *stackptr = &(_stackptr[*stackidx]);
2930 B43_WARN_ON(offset & 0xF000);
2931 B43_WARN_ON(id & 0xF0);
2933 *stackptr |= ((u32) id) << 12;
2934 *stackptr |= ((u32) value) << 16;
2936 B43_WARN_ON(*stackidx >= B43_INTERFSTACK_SIZE);
2939 static u16 _stack_restore(u32 * stackptr, u8 id, u16 offset)
2943 B43_WARN_ON(offset & 0xF000);
2944 B43_WARN_ON(id & 0xF0);
2945 for (i = 0; i < B43_INTERFSTACK_SIZE; i++, stackptr++) {
2946 if ((*stackptr & 0x00000FFF) != offset)
2948 if (((*stackptr & 0x0000F000) >> 12) != id)
2950 return ((*stackptr & 0xFFFF0000) >> 16);
2957 #define phy_stacksave(offset) \
2959 _stack_save(stack, &stackidx, 0x1, (offset), \
2960 b43_phy_read(dev, (offset))); \
2962 #define phy_stackrestore(offset) \
2964 b43_phy_write(dev, (offset), \
2965 _stack_restore(stack, 0x1, \
2968 #define radio_stacksave(offset) \
2970 _stack_save(stack, &stackidx, 0x2, (offset), \
2971 b43_radio_read16(dev, (offset))); \
2973 #define radio_stackrestore(offset) \
2975 b43_radio_write16(dev, (offset), \
2976 _stack_restore(stack, 0x2, \
2979 #define ofdmtab_stacksave(table, offset) \
2981 _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
2982 b43_ofdmtab_read16(dev, (table), (offset))); \
2984 #define ofdmtab_stackrestore(table, offset) \
2986 b43_ofdmtab_write16(dev, (table), (offset), \
2987 _stack_restore(stack, 0x3, \
2988 (offset)|(table))); \
2992 b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
2994 struct b43_phy *phy = &dev->phy;
2996 size_t stackidx = 0;
2997 u32 *stack = phy->interfstack;
3000 case B43_INTERFMODE_NONWLAN:
3001 if (phy->rev != 1) {
3002 b43_phy_write(dev, 0x042B,
3003 b43_phy_read(dev, 0x042B) | 0x0800);
3004 b43_phy_write(dev, B43_PHY_G_CRS,
3006 B43_PHY_G_CRS) & ~0x4000);
3009 radio_stacksave(0x0078);
3010 tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
3011 flipped = flip_4bit(tmp);
3012 if (flipped < 10 && flipped >= 8)
3014 else if (flipped >= 10)
3016 flipped = flip_4bit(flipped);
3017 flipped = (flipped << 1) | 0x0020;
3018 b43_radio_write16(dev, 0x0078, flipped);
3020 b43_calc_nrssi_threshold(dev);
3022 phy_stacksave(0x0406);
3023 b43_phy_write(dev, 0x0406, 0x7E28);
3025 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x0800);
3026 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3028 B43_PHY_RADIO_BITFIELD) | 0x1000);
3030 phy_stacksave(0x04A0);
3031 b43_phy_write(dev, 0x04A0,
3032 (b43_phy_read(dev, 0x04A0) & 0xC0C0) | 0x0008);
3033 phy_stacksave(0x04A1);
3034 b43_phy_write(dev, 0x04A1,
3035 (b43_phy_read(dev, 0x04A1) & 0xC0C0) | 0x0605);
3036 phy_stacksave(0x04A2);
3037 b43_phy_write(dev, 0x04A2,
3038 (b43_phy_read(dev, 0x04A2) & 0xC0C0) | 0x0204);
3039 phy_stacksave(0x04A8);
3040 b43_phy_write(dev, 0x04A8,
3041 (b43_phy_read(dev, 0x04A8) & 0xC0C0) | 0x0803);
3042 phy_stacksave(0x04AB);
3043 b43_phy_write(dev, 0x04AB,
3044 (b43_phy_read(dev, 0x04AB) & 0xC0C0) | 0x0605);
3046 phy_stacksave(0x04A7);
3047 b43_phy_write(dev, 0x04A7, 0x0002);
3048 phy_stacksave(0x04A3);
3049 b43_phy_write(dev, 0x04A3, 0x287A);
3050 phy_stacksave(0x04A9);
3051 b43_phy_write(dev, 0x04A9, 0x2027);
3052 phy_stacksave(0x0493);
3053 b43_phy_write(dev, 0x0493, 0x32F5);
3054 phy_stacksave(0x04AA);
3055 b43_phy_write(dev, 0x04AA, 0x2027);
3056 phy_stacksave(0x04AC);
3057 b43_phy_write(dev, 0x04AC, 0x32F5);
3059 case B43_INTERFMODE_MANUALWLAN:
3060 if (b43_phy_read(dev, 0x0033) & 0x0800)
3063 phy->aci_enable = 1;
3065 phy_stacksave(B43_PHY_RADIO_BITFIELD);
3066 phy_stacksave(B43_PHY_G_CRS);
3068 phy_stacksave(0x0406);
3070 phy_stacksave(0x04C0);
3071 phy_stacksave(0x04C1);
3073 phy_stacksave(0x0033);
3074 phy_stacksave(0x04A7);
3075 phy_stacksave(0x04A3);
3076 phy_stacksave(0x04A9);
3077 phy_stacksave(0x04AA);
3078 phy_stacksave(0x04AC);
3079 phy_stacksave(0x0493);
3080 phy_stacksave(0x04A1);
3081 phy_stacksave(0x04A0);
3082 phy_stacksave(0x04A2);
3083 phy_stacksave(0x048A);
3084 phy_stacksave(0x04A8);
3085 phy_stacksave(0x04AB);
3086 if (phy->rev == 2) {
3087 phy_stacksave(0x04AD);
3088 phy_stacksave(0x04AE);
3089 } else if (phy->rev >= 3) {
3090 phy_stacksave(0x04AD);
3091 phy_stacksave(0x0415);
3092 phy_stacksave(0x0416);
3093 phy_stacksave(0x0417);
3094 ofdmtab_stacksave(0x1A00, 0x2);
3095 ofdmtab_stacksave(0x1A00, 0x3);
3097 phy_stacksave(0x042B);
3098 phy_stacksave(0x048C);
3100 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3101 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3103 b43_phy_write(dev, B43_PHY_G_CRS,
3104 (b43_phy_read(dev, B43_PHY_G_CRS)
3105 & 0xFFFC) | 0x0002);
3107 b43_phy_write(dev, 0x0033, 0x0800);
3108 b43_phy_write(dev, 0x04A3, 0x2027);
3109 b43_phy_write(dev, 0x04A9, 0x1CA8);
3110 b43_phy_write(dev, 0x0493, 0x287A);
3111 b43_phy_write(dev, 0x04AA, 0x1CA8);
3112 b43_phy_write(dev, 0x04AC, 0x287A);
3114 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3115 & 0xFFC0) | 0x001A);
3116 b43_phy_write(dev, 0x04A7, 0x000D);
3119 b43_phy_write(dev, 0x0406, 0xFF0D);
3120 } else if (phy->rev == 2) {
3121 b43_phy_write(dev, 0x04C0, 0xFFFF);
3122 b43_phy_write(dev, 0x04C1, 0x00A9);
3124 b43_phy_write(dev, 0x04C0, 0x00C1);
3125 b43_phy_write(dev, 0x04C1, 0x0059);
3128 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3129 & 0xC0FF) | 0x1800);
3130 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3131 & 0xFFC0) | 0x0015);
3132 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3133 & 0xCFFF) | 0x1000);
3134 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3135 & 0xF0FF) | 0x0A00);
3136 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3137 & 0xCFFF) | 0x1000);
3138 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3139 & 0xF0FF) | 0x0800);
3140 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3141 & 0xFFCF) | 0x0010);
3142 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3143 & 0xFFF0) | 0x0005);
3144 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3145 & 0xFFCF) | 0x0010);
3146 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3147 & 0xFFF0) | 0x0006);
3148 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3149 & 0xF0FF) | 0x0800);
3150 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3151 & 0xF0FF) | 0x0500);
3152 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3153 & 0xFFF0) | 0x000B);
3155 if (phy->rev >= 3) {
3156 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3158 b43_phy_write(dev, 0x0415, (b43_phy_read(dev, 0x0415)
3159 & 0x8000) | 0x36D8);
3160 b43_phy_write(dev, 0x0416, (b43_phy_read(dev, 0x0416)
3161 & 0x8000) | 0x36D8);
3162 b43_phy_write(dev, 0x0417, (b43_phy_read(dev, 0x0417)
3163 & 0xFE00) | 0x016D);
3165 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3167 b43_phy_write(dev, 0x048A, (b43_phy_read(dev, 0x048A)
3168 & 0x9FFF) | 0x2000);
3169 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ACIW);
3171 if (phy->rev >= 2) {
3172 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B)
3175 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
3176 & 0xF0FF) | 0x0200);
3177 if (phy->rev == 2) {
3178 b43_phy_write(dev, 0x04AE, (b43_phy_read(dev, 0x04AE)
3179 & 0xFF00) | 0x007F);
3180 b43_phy_write(dev, 0x04AD, (b43_phy_read(dev, 0x04AD)
3181 & 0x00FF) | 0x1300);
3182 } else if (phy->rev >= 6) {
3183 b43_ofdmtab_write16(dev, 0x1A00, 0x3, 0x007F);
3184 b43_ofdmtab_write16(dev, 0x1A00, 0x2, 0x007F);
3185 b43_phy_write(dev, 0x04AD, b43_phy_read(dev, 0x04AD)
3188 b43_calc_nrssi_slope(dev);
3196 b43_radio_interference_mitigation_disable(struct b43_wldev *dev, int mode)
3198 struct b43_phy *phy = &dev->phy;
3199 u32 *stack = phy->interfstack;
3202 case B43_INTERFMODE_NONWLAN:
3203 if (phy->rev != 1) {
3204 b43_phy_write(dev, 0x042B,
3205 b43_phy_read(dev, 0x042B) & ~0x0800);
3206 b43_phy_write(dev, B43_PHY_G_CRS,
3208 B43_PHY_G_CRS) | 0x4000);
3211 radio_stackrestore(0x0078);
3212 b43_calc_nrssi_threshold(dev);
3213 phy_stackrestore(0x0406);
3214 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) & ~0x0800);
3215 if (!dev->bad_frames_preempt) {
3216 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3217 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3220 b43_phy_write(dev, B43_PHY_G_CRS,
3221 b43_phy_read(dev, B43_PHY_G_CRS) | 0x4000);
3222 phy_stackrestore(0x04A0);
3223 phy_stackrestore(0x04A1);
3224 phy_stackrestore(0x04A2);
3225 phy_stackrestore(0x04A8);
3226 phy_stackrestore(0x04AB);
3227 phy_stackrestore(0x04A7);
3228 phy_stackrestore(0x04A3);
3229 phy_stackrestore(0x04A9);
3230 phy_stackrestore(0x0493);
3231 phy_stackrestore(0x04AA);
3232 phy_stackrestore(0x04AC);
3234 case B43_INTERFMODE_MANUALWLAN:
3235 if (!(b43_phy_read(dev, 0x0033) & 0x0800))
3238 phy->aci_enable = 0;
3240 phy_stackrestore(B43_PHY_RADIO_BITFIELD);
3241 phy_stackrestore(B43_PHY_G_CRS);
3242 phy_stackrestore(0x0033);
3243 phy_stackrestore(0x04A3);
3244 phy_stackrestore(0x04A9);
3245 phy_stackrestore(0x0493);
3246 phy_stackrestore(0x04AA);
3247 phy_stackrestore(0x04AC);
3248 phy_stackrestore(0x04A0);
3249 phy_stackrestore(0x04A7);
3250 if (phy->rev >= 2) {
3251 phy_stackrestore(0x04C0);
3252 phy_stackrestore(0x04C1);
3254 phy_stackrestore(0x0406);
3255 phy_stackrestore(0x04A1);
3256 phy_stackrestore(0x04AB);
3257 phy_stackrestore(0x04A8);
3258 if (phy->rev == 2) {
3259 phy_stackrestore(0x04AD);
3260 phy_stackrestore(0x04AE);
3261 } else if (phy->rev >= 3) {
3262 phy_stackrestore(0x04AD);
3263 phy_stackrestore(0x0415);
3264 phy_stackrestore(0x0416);
3265 phy_stackrestore(0x0417);
3266 ofdmtab_stackrestore(0x1A00, 0x2);
3267 ofdmtab_stackrestore(0x1A00, 0x3);
3269 phy_stackrestore(0x04A2);
3270 phy_stackrestore(0x048A);
3271 phy_stackrestore(0x042B);
3272 phy_stackrestore(0x048C);
3273 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ACIW);
3274 b43_calc_nrssi_slope(dev);
3281 #undef phy_stacksave
3282 #undef phy_stackrestore
3283 #undef radio_stacksave
3284 #undef radio_stackrestore
3285 #undef ofdmtab_stacksave
3286 #undef ofdmtab_stackrestore
3288 int b43_radio_set_interference_mitigation(struct b43_wldev *dev, int mode)
3290 struct b43_phy *phy = &dev->phy;
3293 if ((phy->type != B43_PHYTYPE_G) || (phy->rev == 0) || (!phy->gmode))
3296 phy->aci_wlan_automatic = 0;
3298 case B43_INTERFMODE_AUTOWLAN:
3299 phy->aci_wlan_automatic = 1;
3300 if (phy->aci_enable)
3301 mode = B43_INTERFMODE_MANUALWLAN;
3303 mode = B43_INTERFMODE_NONE;
3305 case B43_INTERFMODE_NONE:
3306 case B43_INTERFMODE_NONWLAN:
3307 case B43_INTERFMODE_MANUALWLAN:
3313 currentmode = phy->interfmode;
3314 if (currentmode == mode)
3316 if (currentmode != B43_INTERFMODE_NONE)
3317 b43_radio_interference_mitigation_disable(dev, currentmode);
3319 if (mode == B43_INTERFMODE_NONE) {
3320 phy->aci_enable = 0;
3321 phy->aci_hw_rssi = 0;
3323 b43_radio_interference_mitigation_enable(dev, mode);
3324 phy->interfmode = mode;
3329 static u16 b43_radio_core_calibration_value(struct b43_wldev *dev)
3331 u16 reg, index, ret;
3333 static const u8 rcc_table[] = {
3334 0x02, 0x03, 0x01, 0x0F,
3335 0x06, 0x07, 0x05, 0x0F,
3336 0x0A, 0x0B, 0x09, 0x0F,
3337 0x0E, 0x0F, 0x0D, 0x0F,
3340 reg = b43_radio_read16(dev, 0x60);
3341 index = (reg & 0x001E) >> 1;
3342 ret = rcc_table[index] << 1;
3343 ret |= (reg & 0x0001);
3349 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
3350 static u16 radio2050_rfover_val(struct b43_wldev *dev,
3351 u16 phy_register, unsigned int lpd)
3353 struct b43_phy *phy = &dev->phy;
3354 struct ssb_sprom *sprom = &(dev->dev->bus->sprom);
3359 if (has_loopback_gain(phy)) {
3360 int max_lb_gain = phy->max_lb_gain;
3364 if (phy->radio_rev == 8)
3365 max_lb_gain += 0x3E;
3367 max_lb_gain += 0x26;
3368 if (max_lb_gain >= 0x46) {
3370 max_lb_gain -= 0x46;
3371 } else if (max_lb_gain >= 0x3A) {
3373 max_lb_gain -= 0x3A;
3374 } else if (max_lb_gain >= 0x2E) {
3376 max_lb_gain -= 0x2E;
3379 max_lb_gain -= 0x10;
3382 for (i = 0; i < 16; i++) {
3383 max_lb_gain -= (i * 6);
3384 if (max_lb_gain < 6)
3388 if ((phy->rev < 7) ||
3389 !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
3390 if (phy_register == B43_PHY_RFOVER) {
3392 } else if (phy_register == B43_PHY_RFOVERVAL) {
3399 return (0x0092 | extlna);
3401 return (0x0093 | extlna);
3407 if (phy_register == B43_PHY_RFOVER) {
3409 } else if (phy_register == B43_PHY_RFOVERVAL) {
3417 return (0x8092 | extlna);
3419 return (0x2092 | extlna);
3421 return (0x2093 | extlna);
3428 if ((phy->rev < 7) ||
3429 !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
3430 if (phy_register == B43_PHY_RFOVER) {
3432 } else if (phy_register == B43_PHY_RFOVERVAL) {
3447 if (phy_register == B43_PHY_RFOVER) {
3449 } else if (phy_register == B43_PHY_RFOVERVAL) {
3468 struct init2050_saved_values {
3469 /* Core registers */
3473 /* Radio registers */
3486 u16 phy_analogoverval;
3494 u16 b43_radio_init2050(struct b43_wldev *dev)
3496 struct b43_phy *phy = &dev->phy;
3497 struct init2050_saved_values sav;
3502 u32 tmp1 = 0, tmp2 = 0;
3504 memset(&sav, 0, sizeof(sav)); /* get rid of "may be used uninitialized..." */
3506 sav.radio_43 = b43_radio_read16(dev, 0x43);
3507 sav.radio_51 = b43_radio_read16(dev, 0x51);
3508 sav.radio_52 = b43_radio_read16(dev, 0x52);
3509 sav.phy_pgactl = b43_phy_read(dev, B43_PHY_PGACTL);
3510 sav.phy_base_5A = b43_phy_read(dev, B43_PHY_BASE(0x5A));
3511 sav.phy_base_59 = b43_phy_read(dev, B43_PHY_BASE(0x59));
3512 sav.phy_base_58 = b43_phy_read(dev, B43_PHY_BASE(0x58));
3514 if (phy->type == B43_PHYTYPE_B) {
3515 sav.phy_base_30 = b43_phy_read(dev, B43_PHY_BASE(0x30));
3516 sav.reg_3EC = b43_read16(dev, 0x3EC);
3518 b43_phy_write(dev, B43_PHY_BASE(0x30), 0xFF);
3519 b43_write16(dev, 0x3EC, 0x3F3F);
3520 } else if (phy->gmode || phy->rev >= 2) {
3521 sav.phy_rfover = b43_phy_read(dev, B43_PHY_RFOVER);
3522 sav.phy_rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
3523 sav.phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
3524 sav.phy_analogoverval =
3525 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
3526 sav.phy_crs0 = b43_phy_read(dev, B43_PHY_CRS0);
3527 sav.phy_classctl = b43_phy_read(dev, B43_PHY_CLASSCTL);
3529 b43_phy_write(dev, B43_PHY_ANALOGOVER,
3530 b43_phy_read(dev, B43_PHY_ANALOGOVER)
3532 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3533 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL)
3535 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
3537 b43_phy_write(dev, B43_PHY_CLASSCTL,
3538 b43_phy_read(dev, B43_PHY_CLASSCTL)
3540 if (has_loopback_gain(phy)) {
3541 sav.phy_lo_mask = b43_phy_read(dev, B43_PHY_LO_MASK);
3542 sav.phy_lo_ctl = b43_phy_read(dev, B43_PHY_LO_CTL);
3545 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
3547 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
3548 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
3551 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3552 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3554 b43_phy_write(dev, B43_PHY_RFOVER,
3555 radio2050_rfover_val(dev, B43_PHY_RFOVER, 0));
3557 b43_write16(dev, 0x3E2, b43_read16(dev, 0x3E2) | 0x8000);
3559 sav.phy_syncctl = b43_phy_read(dev, B43_PHY_SYNCCTL);
3560 b43_phy_write(dev, B43_PHY_SYNCCTL, b43_phy_read(dev, B43_PHY_SYNCCTL)
3562 sav.reg_3E6 = b43_read16(dev, 0x3E6);
3563 sav.reg_3F4 = b43_read16(dev, 0x3F4);
3565 if (phy->analog == 0) {
3566 b43_write16(dev, 0x03E6, 0x0122);
3568 if (phy->analog >= 2) {
3569 b43_phy_write(dev, B43_PHY_BASE(0x03),
3570 (b43_phy_read(dev, B43_PHY_BASE(0x03))
3573 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3574 (b43_read16(dev, B43_MMIO_CHANNEL_EXT) | 0x2000));
3577 rcc = b43_radio_core_calibration_value(dev);
3579 if (phy->type == B43_PHYTYPE_B)
3580 b43_radio_write16(dev, 0x78, 0x26);
3581 if (phy->gmode || phy->rev >= 2) {
3582 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3583 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3586 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFAF);
3587 b43_phy_write(dev, B43_PHY_BASE(0x2B), 0x1403);
3588 if (phy->gmode || phy->rev >= 2) {
3589 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3590 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3593 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFA0);
3594 b43_radio_write16(dev, 0x51, b43_radio_read16(dev, 0x51)
3596 if (phy->radio_rev == 8) {
3597 b43_radio_write16(dev, 0x43, 0x1F);
3599 b43_radio_write16(dev, 0x52, 0);
3600 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
3601 & 0xFFF0) | 0x0009);
3603 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3605 for (i = 0; i < 16; i++) {
3606 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0480);
3607 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3608 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3609 if (phy->gmode || phy->rev >= 2) {
3610 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3611 radio2050_rfover_val(dev,
3615 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3617 if (phy->gmode || phy->rev >= 2) {
3618 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3619 radio2050_rfover_val(dev,
3623 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3625 if (phy->gmode || phy->rev >= 2) {
3626 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3627 radio2050_rfover_val(dev,
3631 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3633 tmp1 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3634 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3635 if (phy->gmode || phy->rev >= 2) {
3636 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3637 radio2050_rfover_val(dev,
3641 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3645 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3649 for (i = 0; i < 16; i++) {
3650 radio78 = ((flip_4bit(i) << 1) | 0x20);
3651 b43_radio_write16(dev, 0x78, radio78);
3653 for (j = 0; j < 16; j++) {
3654 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0D80);
3655 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3656 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3657 if (phy->gmode || phy->rev >= 2) {
3658 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3659 radio2050_rfover_val(dev,
3664 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3666 if (phy->gmode || phy->rev >= 2) {
3667 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3668 radio2050_rfover_val(dev,
3673 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3675 if (phy->gmode || phy->rev >= 2) {
3676 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3677 radio2050_rfover_val(dev,
3682 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3684 tmp2 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3685 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3686 if (phy->gmode || phy->rev >= 2) {
3687 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3688 radio2050_rfover_val(dev,
3693 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3701 /* Restore the registers */
3702 b43_phy_write(dev, B43_PHY_PGACTL, sav.phy_pgactl);
3703 b43_radio_write16(dev, 0x51, sav.radio_51);
3704 b43_radio_write16(dev, 0x52, sav.radio_52);
3705 b43_radio_write16(dev, 0x43, sav.radio_43);
3706 b43_phy_write(dev, B43_PHY_BASE(0x5A), sav.phy_base_5A);
3707 b43_phy_write(dev, B43_PHY_BASE(0x59), sav.phy_base_59);
3708 b43_phy_write(dev, B43_PHY_BASE(0x58), sav.phy_base_58);
3709 b43_write16(dev, 0x3E6, sav.reg_3E6);
3710 if (phy->analog != 0)
3711 b43_write16(dev, 0x3F4, sav.reg_3F4);
3712 b43_phy_write(dev, B43_PHY_SYNCCTL, sav.phy_syncctl);
3713 b43_synth_pu_workaround(dev, phy->channel);
3714 if (phy->type == B43_PHYTYPE_B) {
3715 b43_phy_write(dev, B43_PHY_BASE(0x30), sav.phy_base_30);
3716 b43_write16(dev, 0x3EC, sav.reg_3EC);
3717 } else if (phy->gmode) {
3718 b43_write16(dev, B43_MMIO_PHY_RADIO,
3719 b43_read16(dev, B43_MMIO_PHY_RADIO)
3721 b43_phy_write(dev, B43_PHY_RFOVER, sav.phy_rfover);
3722 b43_phy_write(dev, B43_PHY_RFOVERVAL, sav.phy_rfoverval);
3723 b43_phy_write(dev, B43_PHY_ANALOGOVER, sav.phy_analogover);
3724 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3725 sav.phy_analogoverval);
3726 b43_phy_write(dev, B43_PHY_CRS0, sav.phy_crs0);
3727 b43_phy_write(dev, B43_PHY_CLASSCTL, sav.phy_classctl);
3728 if (has_loopback_gain(phy)) {
3729 b43_phy_write(dev, B43_PHY_LO_MASK, sav.phy_lo_mask);
3730 b43_phy_write(dev, B43_PHY_LO_CTL, sav.phy_lo_ctl);
3741 void b43_radio_init2060(struct b43_wldev *dev)
3745 b43_radio_write16(dev, 0x0004, 0x00C0);
3746 b43_radio_write16(dev, 0x0005, 0x0008);
3747 b43_radio_write16(dev, 0x0009, 0x0040);
3748 b43_radio_write16(dev, 0x0005, 0x00AA);
3749 b43_radio_write16(dev, 0x0032, 0x008F);
3750 b43_radio_write16(dev, 0x0006, 0x008F);
3751 b43_radio_write16(dev, 0x0034, 0x008F);
3752 b43_radio_write16(dev, 0x002C, 0x0007);
3753 b43_radio_write16(dev, 0x0082, 0x0080);
3754 b43_radio_write16(dev, 0x0080, 0x0000);
3755 b43_radio_write16(dev, 0x003F, 0x00DA);
3756 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
3757 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0010);
3758 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
3759 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
3760 msleep(1); /* delay 400usec */
3762 b43_radio_write16(dev, 0x0081,
3763 (b43_radio_read16(dev, 0x0081) & ~0x0020) | 0x0010);
3764 msleep(1); /* delay 400usec */
3766 b43_radio_write16(dev, 0x0005,
3767 (b43_radio_read16(dev, 0x0005) & ~0x0008) | 0x0008);
3768 b43_radio_write16(dev, 0x0085, b43_radio_read16(dev, 0x0085) & ~0x0010);
3769 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
3770 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0040);
3771 b43_radio_write16(dev, 0x0081,
3772 (b43_radio_read16(dev, 0x0081) & ~0x0040) | 0x0040);
3773 b43_radio_write16(dev, 0x0005,
3774 (b43_radio_read16(dev, 0x0081) & ~0x0008) | 0x0008);
3775 b43_phy_write(dev, 0x0063, 0xDDC6);
3776 b43_phy_write(dev, 0x0069, 0x07BE);
3777 b43_phy_write(dev, 0x006A, 0x0000);
3779 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_A, 0);
3785 static inline u16 freq_r3A_value(u16 frequency)
3789 if (frequency < 5091)
3791 else if (frequency < 5321)
3793 else if (frequency < 5806)
3801 void b43_radio_set_tx_iq(struct b43_wldev *dev)
3803 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
3804 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
3805 u16 tmp = b43_radio_read16(dev, 0x001E);
3808 for (i = 0; i < 5; i++) {
3809 for (j = 0; j < 5; j++) {
3810 if (tmp == (data_high[i] << 4 | data_low[j])) {
3811 b43_phy_write(dev, 0x0069,
3812 (i - j) << 8 | 0x00C0);
3819 int b43_radio_selectchannel(struct b43_wldev *dev,
3820 u8 channel, int synthetic_pu_workaround)
3822 struct b43_phy *phy = &dev->phy;
3827 if (channel == 0xFF) {
3828 switch (phy->type) {
3830 channel = B43_DEFAULT_CHANNEL_A;
3834 channel = B43_DEFAULT_CHANNEL_BG;
3841 /* First we set the channel radio code to prevent the
3842 * firmware from sending ghost packets.
3844 channelcookie = channel;
3845 if (phy->type == B43_PHYTYPE_A)
3846 channelcookie |= 0x100;
3847 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
3849 if (phy->type == B43_PHYTYPE_A) {
3852 freq = channel2freq_a(channel);
3854 r8 = b43_radio_read16(dev, 0x0008);
3855 b43_write16(dev, 0x03F0, freq);
3856 b43_radio_write16(dev, 0x0008, r8);
3858 //TODO: write max channel TX power? to Radio 0x2D
3859 tmp = b43_radio_read16(dev, 0x002E);
3861 //TODO: OR tmp with the Power out estimation for this channel?
3862 b43_radio_write16(dev, 0x002E, tmp);
3864 if (freq >= 4920 && freq <= 5500) {
3866 * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
3867 * = (freq * 0.025862069
3869 r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
3871 b43_radio_write16(dev, 0x0007, (r8 << 4) | r8);
3872 b43_radio_write16(dev, 0x0020, (r8 << 4) | r8);
3873 b43_radio_write16(dev, 0x0021, (r8 << 4) | r8);
3874 b43_radio_write16(dev, 0x0022, (b43_radio_read16(dev, 0x0022)
3875 & 0x000F) | (r8 << 4));
3876 b43_radio_write16(dev, 0x002A, (r8 << 4));
3877 b43_radio_write16(dev, 0x002B, (r8 << 4));
3878 b43_radio_write16(dev, 0x0008, (b43_radio_read16(dev, 0x0008)
3879 & 0x00F0) | (r8 << 4));
3880 b43_radio_write16(dev, 0x0029, (b43_radio_read16(dev, 0x0029)
3881 & 0xFF0F) | 0x00B0);
3882 b43_radio_write16(dev, 0x0035, 0x00AA);
3883 b43_radio_write16(dev, 0x0036, 0x0085);
3884 b43_radio_write16(dev, 0x003A, (b43_radio_read16(dev, 0x003A)
3886 freq_r3A_value(freq));
3887 b43_radio_write16(dev, 0x003D,
3888 b43_radio_read16(dev, 0x003D) & 0x00FF);
3889 b43_radio_write16(dev, 0x0081, (b43_radio_read16(dev, 0x0081)
3890 & 0xFF7F) | 0x0080);
3891 b43_radio_write16(dev, 0x0035,
3892 b43_radio_read16(dev, 0x0035) & 0xFFEF);
3893 b43_radio_write16(dev, 0x0035, (b43_radio_read16(dev, 0x0035)
3894 & 0xFFEF) | 0x0010);
3895 b43_radio_set_tx_iq(dev);
3896 //TODO: TSSI2dbm workaround
3897 b43_phy_xmitpower(dev); //FIXME correct?
3899 if ((channel < 1) || (channel > 14))
3902 if (synthetic_pu_workaround)
3903 b43_synth_pu_workaround(dev, channel);
3905 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
3907 if (channel == 14) {
3908 if (dev->dev->bus->sprom.country_code ==
3909 SSB_SPROM1CCODE_JAPAN)
3911 b43_hf_read(dev) & ~B43_HF_ACPR);
3914 b43_hf_read(dev) | B43_HF_ACPR);
3915 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3916 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3919 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3920 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3925 phy->channel = channel;
3926 /* Wait for the radio to tune to the channel and stabilize. */
3932 void b43_radio_turn_on(struct b43_wldev *dev)
3934 struct b43_phy *phy = &dev->phy;
3943 switch (phy->type) {
3945 b43_radio_write16(dev, 0x0004, 0x00C0);
3946 b43_radio_write16(dev, 0x0005, 0x0008);
3947 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) & 0xFFF7);
3948 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) & 0xFFF7);
3949 b43_radio_init2060(dev);
3953 b43_phy_write(dev, 0x0015, 0x8000);
3954 b43_phy_write(dev, 0x0015, 0xCC00);
3955 b43_phy_write(dev, 0x0015, (phy->gmode ? 0x00C0 : 0x0000));
3956 if (phy->radio_off_context.valid) {
3957 /* Restore the RFover values. */
3958 b43_phy_write(dev, B43_PHY_RFOVER,
3959 phy->radio_off_context.rfover);
3960 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3961 phy->radio_off_context.rfoverval);
3962 phy->radio_off_context.valid = 0;
3964 channel = phy->channel;
3965 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_BG, 1);
3966 err |= b43_radio_selectchannel(dev, channel, 0);
3975 void b43_radio_turn_off(struct b43_wldev *dev, bool force)
3977 struct b43_phy *phy = &dev->phy;
3979 if (!phy->radio_on && !force)
3982 if (phy->type == B43_PHYTYPE_A) {
3983 b43_radio_write16(dev, 0x0004, 0x00FF);
3984 b43_radio_write16(dev, 0x0005, 0x00FB);
3985 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) | 0x0008);
3986 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) | 0x0008);
3988 if (phy->type == B43_PHYTYPE_G && dev->dev->id.revision >= 5) {
3989 u16 rfover, rfoverval;
3991 rfover = b43_phy_read(dev, B43_PHY_RFOVER);
3992 rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
3994 phy->radio_off_context.rfover = rfover;
3995 phy->radio_off_context.rfoverval = rfoverval;
3996 phy->radio_off_context.valid = 1;
3998 b43_phy_write(dev, B43_PHY_RFOVER, rfover | 0x008C);
3999 b43_phy_write(dev, B43_PHY_RFOVERVAL, rfoverval & 0xFF73);
4001 b43_phy_write(dev, 0x0015, 0xAA00);