3 Broadcom B43 wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Copyright (c) 2005, 2006 Stefano Brivio <st3@riseup.net>
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>
38 static const s8 b43_tssi2dbm_b_table[] = {
39 0x4D, 0x4C, 0x4B, 0x4A,
40 0x4A, 0x49, 0x48, 0x47,
41 0x47, 0x46, 0x45, 0x45,
42 0x44, 0x43, 0x42, 0x42,
43 0x41, 0x40, 0x3F, 0x3E,
44 0x3D, 0x3C, 0x3B, 0x3A,
45 0x39, 0x38, 0x37, 0x36,
46 0x35, 0x34, 0x32, 0x31,
47 0x30, 0x2F, 0x2D, 0x2C,
48 0x2B, 0x29, 0x28, 0x26,
49 0x25, 0x23, 0x21, 0x1F,
50 0x1D, 0x1A, 0x17, 0x14,
51 0x10, 0x0C, 0x06, 0x00,
57 static const s8 b43_tssi2dbm_g_table[] = {
76 const u8 b43_radio_channel_codes_bg[] = {
83 static void b43_phy_initg(struct b43_wldev *dev);
85 /* Reverse the bits of a 4bit value.
86 * Example: 1101 is flipped 1011
88 static u16 flip_4bit(u16 value)
92 B43_WARN_ON(value & ~0x000F);
94 flipped |= (value & 0x0001) << 3;
95 flipped |= (value & 0x0002) << 1;
96 flipped |= (value & 0x0004) >> 1;
97 flipped |= (value & 0x0008) >> 3;
102 static void generate_rfatt_list(struct b43_wldev *dev,
103 struct b43_rfatt_list *list)
105 struct b43_phy *phy = &dev->phy;
107 /* APHY.rev < 5 || GPHY.rev < 6 */
108 static const struct b43_rfatt rfatt_0[] = {
109 {.att = 3,.with_padmix = 0,},
110 {.att = 1,.with_padmix = 0,},
111 {.att = 5,.with_padmix = 0,},
112 {.att = 7,.with_padmix = 0,},
113 {.att = 9,.with_padmix = 0,},
114 {.att = 2,.with_padmix = 0,},
115 {.att = 0,.with_padmix = 0,},
116 {.att = 4,.with_padmix = 0,},
117 {.att = 6,.with_padmix = 0,},
118 {.att = 8,.with_padmix = 0,},
119 {.att = 1,.with_padmix = 1,},
120 {.att = 2,.with_padmix = 1,},
121 {.att = 3,.with_padmix = 1,},
122 {.att = 4,.with_padmix = 1,},
124 /* Radio.rev == 8 && Radio.version == 0x2050 */
125 static const struct b43_rfatt rfatt_1[] = {
126 {.att = 2,.with_padmix = 1,},
127 {.att = 4,.with_padmix = 1,},
128 {.att = 6,.with_padmix = 1,},
129 {.att = 8,.with_padmix = 1,},
130 {.att = 10,.with_padmix = 1,},
131 {.att = 12,.with_padmix = 1,},
132 {.att = 14,.with_padmix = 1,},
135 static const struct b43_rfatt rfatt_2[] = {
136 {.att = 0,.with_padmix = 1,},
137 {.att = 2,.with_padmix = 1,},
138 {.att = 4,.with_padmix = 1,},
139 {.att = 6,.with_padmix = 1,},
140 {.att = 8,.with_padmix = 1,},
141 {.att = 9,.with_padmix = 1,},
142 {.att = 9,.with_padmix = 1,},
145 if ((phy->type == B43_PHYTYPE_A && phy->rev < 5) ||
146 (phy->type == B43_PHYTYPE_G && phy->rev < 6)) {
148 list->list = rfatt_0;
149 list->len = ARRAY_SIZE(rfatt_0);
154 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
156 list->list = rfatt_1;
157 list->len = ARRAY_SIZE(rfatt_1);
163 list->list = rfatt_2;
164 list->len = ARRAY_SIZE(rfatt_2);
169 static void generate_bbatt_list(struct b43_wldev *dev,
170 struct b43_bbatt_list *list)
172 static const struct b43_bbatt bbatt_0[] = {
184 list->list = bbatt_0;
185 list->len = ARRAY_SIZE(bbatt_0);
190 bool b43_has_hardware_pctl(struct b43_phy *phy)
192 if (!phy->hardware_power_control)
209 static void b43_shm_clear_tssi(struct b43_wldev *dev)
211 struct b43_phy *phy = &dev->phy;
215 b43_shm_write16(dev, B43_SHM_SHARED, 0x0068, 0x7F7F);
216 b43_shm_write16(dev, B43_SHM_SHARED, 0x006a, 0x7F7F);
220 b43_shm_write16(dev, B43_SHM_SHARED, 0x0058, 0x7F7F);
221 b43_shm_write16(dev, B43_SHM_SHARED, 0x005a, 0x7F7F);
222 b43_shm_write16(dev, B43_SHM_SHARED, 0x0070, 0x7F7F);
223 b43_shm_write16(dev, B43_SHM_SHARED, 0x0072, 0x7F7F);
228 void b43_raw_phy_lock(struct b43_wldev *dev)
230 struct b43_phy *phy = &dev->phy;
232 B43_WARN_ON(!irqs_disabled());
234 /* We had a check for MACCTL==0 here, but I think that doesn't
235 * make sense, as MACCTL is never 0 when this is called.
237 B43_WARN_ON(b43_read32(dev, B43_MMIO_MACCTL) == 0);
239 if (dev->dev->id.revision < 3) {
240 b43_mac_suspend(dev);
241 spin_lock(&phy->lock);
243 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
244 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
249 void b43_raw_phy_unlock(struct b43_wldev *dev)
251 struct b43_phy *phy = &dev->phy;
253 B43_WARN_ON(!irqs_disabled());
254 if (dev->dev->id.revision < 3) {
256 spin_unlock(&phy->lock);
260 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
261 b43_power_saving_ctl_bits(dev, 0);
266 /* Different PHYs require different register routing flags.
267 * This adjusts (and does sanity checks on) the routing flags.
269 static inline u16 adjust_phyreg_for_phytype(struct b43_phy *phy,
270 u16 offset, struct b43_wldev *dev)
272 if (phy->type == B43_PHYTYPE_A) {
273 /* OFDM registers are base-registers for the A-PHY. */
274 offset &= ~B43_PHYROUTE_OFDM_GPHY;
276 if (offset & B43_PHYROUTE_EXT_GPHY) {
277 /* Ext-G registers are only available on G-PHYs */
278 if (phy->type != B43_PHYTYPE_G) {
279 b43dbg(dev->wl, "EXT-G PHY access at "
280 "0x%04X on %u type PHY\n", offset, phy->type);
287 u16 b43_phy_read(struct b43_wldev * dev, u16 offset)
289 struct b43_phy *phy = &dev->phy;
291 offset = adjust_phyreg_for_phytype(phy, offset, dev);
292 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
293 return b43_read16(dev, B43_MMIO_PHY_DATA);
296 void b43_phy_write(struct b43_wldev *dev, u16 offset, u16 val)
298 struct b43_phy *phy = &dev->phy;
300 offset = adjust_phyreg_for_phytype(phy, offset, dev);
301 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
303 b43_write16(dev, B43_MMIO_PHY_DATA, val);
306 static void b43_radio_set_txpower_a(struct b43_wldev *dev, u16 txpower);
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_agcsetup(struct b43_wldev *dev)
768 struct b43_phy *phy = &dev->phy;
774 b43_ofdmtab_write16(dev, offset, 0, 0x00FE);
775 b43_ofdmtab_write16(dev, offset, 1, 0x000D);
776 b43_ofdmtab_write16(dev, offset, 2, 0x0013);
777 b43_ofdmtab_write16(dev, offset, 3, 0x0019);
780 b43_ofdmtab_write16(dev, 0x1800, 0, 0x2710);
781 b43_ofdmtab_write16(dev, 0x1801, 0, 0x9B83);
782 b43_ofdmtab_write16(dev, 0x1802, 0, 0x9B83);
783 b43_ofdmtab_write16(dev, 0x1803, 0, 0x0F8D);
784 b43_phy_write(dev, 0x0455, 0x0004);
787 b43_phy_write(dev, 0x04A5, (b43_phy_read(dev, 0x04A5)
789 b43_phy_write(dev, 0x041A, (b43_phy_read(dev, 0x041A)
791 b43_phy_write(dev, 0x041A, (b43_phy_read(dev, 0x041A)
793 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
796 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
799 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
801 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
803 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
805 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
809 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
813 b43_phy_write(dev, 0x0488, (b43_phy_read(dev, 0x0488)
815 b43_phy_write(dev, 0x0488, (b43_phy_read(dev, 0x0488)
817 b43_phy_write(dev, 0x0496, (b43_phy_read(dev, 0x0496)
819 b43_phy_write(dev, 0x0489, (b43_phy_read(dev, 0x0489)
821 b43_phy_write(dev, 0x0489, (b43_phy_read(dev, 0x0489)
823 b43_phy_write(dev, 0x0482, (b43_phy_read(dev, 0x0482)
825 b43_phy_write(dev, 0x0496, (b43_phy_read(dev, 0x0496)
827 b43_phy_write(dev, 0x0481, (b43_phy_read(dev, 0x0481)
829 b43_phy_write(dev, 0x0481, (b43_phy_read(dev, 0x0481)
833 b43_phy_write(dev, 0x0430, 0x092B);
834 b43_phy_write(dev, 0x041B, (b43_phy_read(dev, 0x041B)
837 b43_phy_write(dev, 0x041B, b43_phy_read(dev, 0x041B)
839 b43_phy_write(dev, 0x041F, 0x287A);
840 b43_phy_write(dev, 0x0420, (b43_phy_read(dev, 0x0420)
845 b43_phy_write(dev, 0x0422, 0x287A);
846 b43_phy_write(dev, 0x0420, (b43_phy_read(dev, 0x0420)
850 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
852 b43_phy_write(dev, 0x048E, 0x1C00);
857 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
859 b43_phy_write(dev, 0x048B, 0x005E);
860 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
862 b43_phy_write(dev, 0x048D, 0x0002);
864 b43_ofdmtab_write16(dev, offset, 0, 0x00);
865 b43_ofdmtab_write16(dev, offset, 1, 0x07);
866 b43_ofdmtab_write16(dev, offset, 2, 0x10);
867 b43_ofdmtab_write16(dev, offset, 3, 0x1C);
870 b43_phy_write(dev, 0x0426, b43_phy_read(dev, 0x0426)
872 b43_phy_write(dev, 0x0426, b43_phy_read(dev, 0x0426)
877 static void b43_phy_setupg(struct b43_wldev *dev)
879 struct ssb_bus *bus = dev->dev->bus;
880 struct b43_phy *phy = &dev->phy;
883 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
885 b43_phy_write(dev, 0x0406, 0x4F19);
886 b43_phy_write(dev, B43_PHY_G_CRS,
887 (b43_phy_read(dev, B43_PHY_G_CRS) & 0xFC3F) |
889 b43_phy_write(dev, 0x042C, 0x005A);
890 b43_phy_write(dev, 0x0427, 0x001A);
892 for (i = 0; i < B43_TAB_FINEFREQG_SIZE; i++)
893 b43_ofdmtab_write16(dev, 0x5800, i,
894 b43_tab_finefreqg[i]);
895 for (i = 0; i < B43_TAB_NOISEG1_SIZE; i++)
896 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noiseg1[i]);
897 for (i = 0; i < B43_TAB_ROTOR_SIZE; i++)
898 b43_ofdmtab_write16(dev, 0x2000, i, b43_tab_rotor[i]);
900 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
901 b43_nrssi_hw_write(dev, 0xBA98, (s16) 0x7654);
904 b43_phy_write(dev, 0x04C0, 0x1861);
905 b43_phy_write(dev, 0x04C1, 0x0271);
906 } else if (phy->rev > 2) {
907 b43_phy_write(dev, 0x04C0, 0x0098);
908 b43_phy_write(dev, 0x04C1, 0x0070);
909 b43_phy_write(dev, 0x04C9, 0x0080);
911 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x800);
913 for (i = 0; i < 64; i++)
914 b43_ofdmtab_write16(dev, 0x4000, i, i);
915 for (i = 0; i < B43_TAB_NOISEG2_SIZE; i++)
916 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noiseg2[i]);
920 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
921 b43_ofdmtab_write16(dev, 0x1400, i,
922 b43_tab_noisescaleg1[i]);
923 else if ((phy->rev >= 7) && (b43_phy_read(dev, 0x0449) & 0x0200))
924 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
925 b43_ofdmtab_write16(dev, 0x1400, i,
926 b43_tab_noisescaleg3[i]);
928 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
929 b43_ofdmtab_write16(dev, 0x1400, i,
930 b43_tab_noisescaleg2[i]);
933 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++)
934 b43_ofdmtab_write16(dev, 0x5000, i,
935 b43_tab_sigmasqr1[i]);
936 else if ((phy->rev > 2) && (phy->rev <= 8))
937 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++)
938 b43_ofdmtab_write16(dev, 0x5000, i,
939 b43_tab_sigmasqr2[i]);
942 for (i = 0; i < B43_TAB_RETARD_SIZE; i++)
943 b43_ofdmtab_write32(dev, 0x2400, i, b43_tab_retard[i]);
944 for (i = 4; i < 20; i++)
945 b43_ofdmtab_write16(dev, 0x5400, i, 0x0020);
946 b43_phy_agcsetup(dev);
948 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
949 (bus->boardinfo.type == SSB_BOARD_BU4306) &&
950 (bus->boardinfo.rev == 0x17))
953 b43_ofdmtab_write16(dev, 0x5001, 0, 0x0002);
954 b43_ofdmtab_write16(dev, 0x5002, 0, 0x0001);
956 for (i = 0; i < 0x20; i++)
957 b43_ofdmtab_write16(dev, 0x1000, i, 0x0820);
958 b43_phy_agcsetup(dev);
959 b43_phy_read(dev, 0x0400); /* dummy read */
960 b43_phy_write(dev, 0x0403, 0x1000);
961 b43_ofdmtab_write16(dev, 0x3C02, 0, 0x000F);
962 b43_ofdmtab_write16(dev, 0x3C03, 0, 0x0014);
964 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
965 (bus->boardinfo.type == SSB_BOARD_BU4306) &&
966 (bus->boardinfo.rev == 0x17))
969 b43_ofdmtab_write16(dev, 0x0401, 0, 0x0002);
970 b43_ofdmtab_write16(dev, 0x0402, 0, 0x0001);
974 /* Initialize the noisescaletable for APHY */
975 static void b43_phy_init_noisescaletbl(struct b43_wldev *dev)
977 struct b43_phy *phy = &dev->phy;
980 for (i = 0; i < 12; i++) {
982 b43_ofdmtab_write16(dev, 0x1400, i, 0x6767);
984 b43_ofdmtab_write16(dev, 0x1400, i, 0x2323);
987 b43_ofdmtab_write16(dev, 0x1400, i, 0x6700);
989 b43_ofdmtab_write16(dev, 0x1400, i, 0x2300);
990 for (i = 0; i < 11; i++) {
992 b43_ofdmtab_write16(dev, 0x1400, i, 0x6767);
994 b43_ofdmtab_write16(dev, 0x1400, i, 0x2323);
997 b43_ofdmtab_write16(dev, 0x1400, i, 0x0067);
999 b43_ofdmtab_write16(dev, 0x1400, i, 0x0023);
1002 static void b43_phy_setupa(struct b43_wldev *dev)
1004 struct b43_phy *phy = &dev->phy;
1007 B43_WARN_ON(phy->type != B43_PHYTYPE_A);
1010 b43_phy_write(dev, 0x008E, 0x3800);
1011 b43_phy_write(dev, 0x0035, 0x03FF);
1012 b43_phy_write(dev, 0x0036, 0x0400);
1014 b43_ofdmtab_write16(dev, 0x3807, 0, 0x0051);
1016 b43_phy_write(dev, 0x001C, 0x0FF9);
1017 b43_phy_write(dev, 0x0020, b43_phy_read(dev, 0x0020) & 0xFF0F);
1018 b43_ofdmtab_write16(dev, 0x3C0C, 0, 0x07BF);
1019 b43_radio_write16(dev, 0x0002, 0x07BF);
1021 b43_phy_write(dev, 0x0024, 0x4680);
1022 b43_phy_write(dev, 0x0020, 0x0003);
1023 b43_phy_write(dev, 0x001D, 0x0F40);
1024 b43_phy_write(dev, 0x001F, 0x1C00);
1026 b43_phy_write(dev, 0x002A, (b43_phy_read(dev, 0x002A)
1027 & 0x00FF) | 0x0400);
1028 b43_phy_write(dev, 0x002B, b43_phy_read(dev, 0x002B)
1030 b43_phy_write(dev, 0x008E, 0x58C1);
1032 b43_ofdmtab_write16(dev, 0x0803, 0, 0x000F);
1033 b43_ofdmtab_write16(dev, 0x0804, 0, 0x001F);
1034 b43_ofdmtab_write16(dev, 0x0805, 0, 0x002A);
1035 b43_ofdmtab_write16(dev, 0x0805, 0, 0x0030);
1036 b43_ofdmtab_write16(dev, 0x0807, 0, 0x003A);
1038 b43_ofdmtab_write16(dev, 0x0000, 0, 0x0013);
1039 b43_ofdmtab_write16(dev, 0x0000, 1, 0x0013);
1040 b43_ofdmtab_write16(dev, 0x0000, 2, 0x0013);
1041 b43_ofdmtab_write16(dev, 0x0000, 3, 0x0013);
1042 b43_ofdmtab_write16(dev, 0x0000, 4, 0x0015);
1043 b43_ofdmtab_write16(dev, 0x0000, 5, 0x0015);
1044 b43_ofdmtab_write16(dev, 0x0000, 6, 0x0019);
1046 b43_ofdmtab_write16(dev, 0x0404, 0, 0x0003);
1047 b43_ofdmtab_write16(dev, 0x0405, 0, 0x0003);
1048 b43_ofdmtab_write16(dev, 0x0406, 0, 0x0007);
1050 for (i = 0; i < 16; i++)
1051 b43_ofdmtab_write16(dev, 0x4000, i, (0x8 + i) & 0x000F);
1053 b43_ofdmtab_write16(dev, 0x3003, 0, 0x1044);
1054 b43_ofdmtab_write16(dev, 0x3004, 0, 0x7201);
1055 b43_ofdmtab_write16(dev, 0x3006, 0, 0x0040);
1056 b43_ofdmtab_write16(dev, 0x3001, 0,
1057 (b43_ofdmtab_read16(dev, 0x3001, 0) &
1060 for (i = 0; i < B43_TAB_FINEFREQA_SIZE; i++)
1061 b43_ofdmtab_write16(dev, 0x5800, i,
1062 b43_tab_finefreqa[i]);
1063 for (i = 0; i < B43_TAB_NOISEA2_SIZE; i++)
1064 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noisea2[i]);
1065 for (i = 0; i < B43_TAB_ROTOR_SIZE; i++)
1066 b43_ofdmtab_write32(dev, 0x2000, i, b43_tab_rotor[i]);
1067 b43_phy_init_noisescaletbl(dev);
1068 for (i = 0; i < B43_TAB_RETARD_SIZE; i++)
1069 b43_ofdmtab_write32(dev, 0x2400, i, b43_tab_retard[i]);
1072 for (i = 0; i < 64; i++)
1073 b43_ofdmtab_write16(dev, 0x4000, i, i);
1075 b43_ofdmtab_write16(dev, 0x3807, 0, 0x0051);
1077 b43_phy_write(dev, 0x001C, 0x0FF9);
1078 b43_phy_write(dev, 0x0020, b43_phy_read(dev, 0x0020) & 0xFF0F);
1079 b43_radio_write16(dev, 0x0002, 0x07BF);
1081 b43_phy_write(dev, 0x0024, 0x4680);
1082 b43_phy_write(dev, 0x0020, 0x0003);
1083 b43_phy_write(dev, 0x001D, 0x0F40);
1084 b43_phy_write(dev, 0x001F, 0x1C00);
1085 b43_phy_write(dev, 0x002A, (b43_phy_read(dev, 0x002A)
1086 & 0x00FF) | 0x0400);
1088 b43_ofdmtab_write16(dev, 0x3000, 1,
1089 (b43_ofdmtab_read16(dev, 0x3000, 1)
1090 & 0x0010) | 0x0008);
1091 for (i = 0; i < B43_TAB_NOISEA3_SIZE; i++) {
1092 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noisea3[i]);
1094 b43_phy_init_noisescaletbl(dev);
1095 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++) {
1096 b43_ofdmtab_write16(dev, 0x5000, i,
1097 b43_tab_sigmasqr1[i]);
1100 b43_phy_write(dev, 0x0003, 0x1808);
1102 b43_ofdmtab_write16(dev, 0x0803, 0, 0x000F);
1103 b43_ofdmtab_write16(dev, 0x0804, 0, 0x001F);
1104 b43_ofdmtab_write16(dev, 0x0805, 0, 0x002A);
1105 b43_ofdmtab_write16(dev, 0x0805, 0, 0x0030);
1106 b43_ofdmtab_write16(dev, 0x0807, 0, 0x003A);
1108 b43_ofdmtab_write16(dev, 0x0000, 0, 0x0013);
1109 b43_ofdmtab_write16(dev, 0x0001, 0, 0x0013);
1110 b43_ofdmtab_write16(dev, 0x0002, 0, 0x0013);
1111 b43_ofdmtab_write16(dev, 0x0003, 0, 0x0013);
1112 b43_ofdmtab_write16(dev, 0x0004, 0, 0x0015);
1113 b43_ofdmtab_write16(dev, 0x0005, 0, 0x0015);
1114 b43_ofdmtab_write16(dev, 0x0006, 0, 0x0019);
1116 b43_ofdmtab_write16(dev, 0x0404, 0, 0x0003);
1117 b43_ofdmtab_write16(dev, 0x0405, 0, 0x0003);
1118 b43_ofdmtab_write16(dev, 0x0406, 0, 0x0007);
1120 b43_ofdmtab_write16(dev, 0x3C02, 0, 0x000F);
1121 b43_ofdmtab_write16(dev, 0x3C03, 0, 0x0014);
1128 /* Initialize APHY. This is also called for the GPHY in some cases. */
1129 static void b43_phy_inita(struct b43_wldev *dev)
1131 struct ssb_bus *bus = dev->dev->bus;
1132 struct b43_phy *phy = &dev->phy;
1137 if (phy->type == B43_PHYTYPE_A) {
1138 b43_phy_setupa(dev);
1140 b43_phy_setupg(dev);
1142 (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_PACTRL))
1143 b43_phy_write(dev, 0x046E, 0x03CF);
1147 b43_phy_write(dev, B43_PHY_A_CRS,
1148 (b43_phy_read(dev, B43_PHY_A_CRS) & 0xF83C) | 0x0340);
1149 b43_phy_write(dev, 0x0034, 0x0001);
1152 b43_phy_write(dev, B43_PHY_A_CRS,
1153 b43_phy_read(dev, B43_PHY_A_CRS) | (1 << 14));
1154 b43_radio_init2060(dev);
1156 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1157 ((bus->boardinfo.type == SSB_BOARD_BU4306) ||
1158 (bus->boardinfo.type == SSB_BOARD_BU4309))) {
1159 if (phy->lofcal == 0xFFFF) {
1161 b43_radio_set_tx_iq(dev);
1163 b43_radio_write16(dev, 0x001E, phy->lofcal);
1166 b43_phy_write(dev, 0x007A, 0xF111);
1168 if (phy->cur_idle_tssi == 0) {
1169 b43_radio_write16(dev, 0x0019, 0x0000);
1170 b43_radio_write16(dev, 0x0017, 0x0020);
1172 tval = b43_ofdmtab_read16(dev, 0x3001, 0);
1173 if (phy->rev == 1) {
1174 b43_ofdmtab_write16(dev, 0x3001, 0,
1175 (b43_ofdmtab_read16(dev, 0x3001, 0)
1179 b43_ofdmtab_write16(dev, 0x3001, 0,
1180 (b43_ofdmtab_read16(dev, 0x3001, 0)
1184 b43_dummy_transmission(dev);
1185 phy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_A_PCTL);
1186 b43_ofdmtab_write16(dev, 0x3001, 0, tval);
1188 b43_radio_set_txpower_a(dev, 0x0018);
1190 b43_shm_clear_tssi(dev);
1193 static void b43_phy_initb2(struct b43_wldev *dev)
1195 struct b43_phy *phy = &dev->phy;
1198 b43_write16(dev, 0x03EC, 0x3F22);
1199 b43_phy_write(dev, 0x0020, 0x301C);
1200 b43_phy_write(dev, 0x0026, 0x0000);
1201 b43_phy_write(dev, 0x0030, 0x00C6);
1202 b43_phy_write(dev, 0x0088, 0x3E00);
1204 for (offset = 0x0089; offset < 0x00A7; offset++) {
1205 b43_phy_write(dev, offset, val);
1208 b43_phy_write(dev, 0x03E4, 0x3000);
1209 b43_radio_selectchannel(dev, phy->channel, 0);
1210 if (phy->radio_ver != 0x2050) {
1211 b43_radio_write16(dev, 0x0075, 0x0080);
1212 b43_radio_write16(dev, 0x0079, 0x0081);
1214 b43_radio_write16(dev, 0x0050, 0x0020);
1215 b43_radio_write16(dev, 0x0050, 0x0023);
1216 if (phy->radio_ver == 0x2050) {
1217 b43_radio_write16(dev, 0x0050, 0x0020);
1218 b43_radio_write16(dev, 0x005A, 0x0070);
1219 b43_radio_write16(dev, 0x005B, 0x007B);
1220 b43_radio_write16(dev, 0x005C, 0x00B0);
1221 b43_radio_write16(dev, 0x007A, 0x000F);
1222 b43_phy_write(dev, 0x0038, 0x0677);
1223 b43_radio_init2050(dev);
1225 b43_phy_write(dev, 0x0014, 0x0080);
1226 b43_phy_write(dev, 0x0032, 0x00CA);
1227 b43_phy_write(dev, 0x0032, 0x00CC);
1228 b43_phy_write(dev, 0x0035, 0x07C2);
1229 b43_lo_b_measure(dev);
1230 b43_phy_write(dev, 0x0026, 0xCC00);
1231 if (phy->radio_ver != 0x2050)
1232 b43_phy_write(dev, 0x0026, 0xCE00);
1233 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1000);
1234 b43_phy_write(dev, 0x002A, 0x88A3);
1235 if (phy->radio_ver != 0x2050)
1236 b43_phy_write(dev, 0x002A, 0x88C2);
1237 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1238 b43_phy_init_pctl(dev);
1241 static void b43_phy_initb4(struct b43_wldev *dev)
1243 struct b43_phy *phy = &dev->phy;
1246 b43_write16(dev, 0x03EC, 0x3F22);
1247 b43_phy_write(dev, 0x0020, 0x301C);
1248 b43_phy_write(dev, 0x0026, 0x0000);
1249 b43_phy_write(dev, 0x0030, 0x00C6);
1250 b43_phy_write(dev, 0x0088, 0x3E00);
1252 for (offset = 0x0089; offset < 0x00A7; offset++) {
1253 b43_phy_write(dev, offset, val);
1256 b43_phy_write(dev, 0x03E4, 0x3000);
1257 b43_radio_selectchannel(dev, phy->channel, 0);
1258 if (phy->radio_ver != 0x2050) {
1259 b43_radio_write16(dev, 0x0075, 0x0080);
1260 b43_radio_write16(dev, 0x0079, 0x0081);
1262 b43_radio_write16(dev, 0x0050, 0x0020);
1263 b43_radio_write16(dev, 0x0050, 0x0023);
1264 if (phy->radio_ver == 0x2050) {
1265 b43_radio_write16(dev, 0x0050, 0x0020);
1266 b43_radio_write16(dev, 0x005A, 0x0070);
1267 b43_radio_write16(dev, 0x005B, 0x007B);
1268 b43_radio_write16(dev, 0x005C, 0x00B0);
1269 b43_radio_write16(dev, 0x007A, 0x000F);
1270 b43_phy_write(dev, 0x0038, 0x0677);
1271 b43_radio_init2050(dev);
1273 b43_phy_write(dev, 0x0014, 0x0080);
1274 b43_phy_write(dev, 0x0032, 0x00CA);
1275 if (phy->radio_ver == 0x2050)
1276 b43_phy_write(dev, 0x0032, 0x00E0);
1277 b43_phy_write(dev, 0x0035, 0x07C2);
1279 b43_lo_b_measure(dev);
1281 b43_phy_write(dev, 0x0026, 0xCC00);
1282 if (phy->radio_ver == 0x2050)
1283 b43_phy_write(dev, 0x0026, 0xCE00);
1284 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1100);
1285 b43_phy_write(dev, 0x002A, 0x88A3);
1286 if (phy->radio_ver == 0x2050)
1287 b43_phy_write(dev, 0x002A, 0x88C2);
1288 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1289 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI) {
1290 b43_calc_nrssi_slope(dev);
1291 b43_calc_nrssi_threshold(dev);
1293 b43_phy_init_pctl(dev);
1296 static void b43_phy_initb5(struct b43_wldev *dev)
1298 struct ssb_bus *bus = dev->dev->bus;
1299 struct b43_phy *phy = &dev->phy;
1303 if (phy->analog == 1) {
1304 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
1307 if ((bus->boardinfo.vendor != SSB_BOARDVENDOR_BCM) &&
1308 (bus->boardinfo.type != SSB_BOARD_BU4306)) {
1310 for (offset = 0x00A8; offset < 0x00C7; offset++) {
1311 b43_phy_write(dev, offset, value);
1315 b43_phy_write(dev, 0x0035, (b43_phy_read(dev, 0x0035) & 0xF0FF)
1317 if (phy->radio_ver == 0x2050)
1318 b43_phy_write(dev, 0x0038, 0x0667);
1320 if (phy->gmode || phy->rev >= 2) {
1321 if (phy->radio_ver == 0x2050) {
1322 b43_radio_write16(dev, 0x007A,
1323 b43_radio_read16(dev, 0x007A)
1325 b43_radio_write16(dev, 0x0051,
1326 b43_radio_read16(dev, 0x0051)
1329 b43_write16(dev, B43_MMIO_PHY_RADIO, 0x0000);
1331 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1332 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1334 b43_phy_write(dev, 0x001C, 0x186A);
1336 b43_phy_write(dev, 0x0013,
1337 (b43_phy_read(dev, 0x0013) & 0x00FF) | 0x1900);
1338 b43_phy_write(dev, 0x0035,
1339 (b43_phy_read(dev, 0x0035) & 0xFFC0) | 0x0064);
1340 b43_phy_write(dev, 0x005D,
1341 (b43_phy_read(dev, 0x005D) & 0xFF80) | 0x000A);
1344 if (dev->bad_frames_preempt) {
1345 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
1347 B43_PHY_RADIO_BITFIELD) | (1 << 11));
1350 if (phy->analog == 1) {
1351 b43_phy_write(dev, 0x0026, 0xCE00);
1352 b43_phy_write(dev, 0x0021, 0x3763);
1353 b43_phy_write(dev, 0x0022, 0x1BC3);
1354 b43_phy_write(dev, 0x0023, 0x06F9);
1355 b43_phy_write(dev, 0x0024, 0x037E);
1357 b43_phy_write(dev, 0x0026, 0xCC00);
1358 b43_phy_write(dev, 0x0030, 0x00C6);
1359 b43_write16(dev, 0x03EC, 0x3F22);
1361 if (phy->analog == 1)
1362 b43_phy_write(dev, 0x0020, 0x3E1C);
1364 b43_phy_write(dev, 0x0020, 0x301C);
1366 if (phy->analog == 0)
1367 b43_write16(dev, 0x03E4, 0x3000);
1369 old_channel = phy->channel;
1370 /* Force to channel 7, even if not supported. */
1371 b43_radio_selectchannel(dev, 7, 0);
1373 if (phy->radio_ver != 0x2050) {
1374 b43_radio_write16(dev, 0x0075, 0x0080);
1375 b43_radio_write16(dev, 0x0079, 0x0081);
1378 b43_radio_write16(dev, 0x0050, 0x0020);
1379 b43_radio_write16(dev, 0x0050, 0x0023);
1381 if (phy->radio_ver == 0x2050) {
1382 b43_radio_write16(dev, 0x0050, 0x0020);
1383 b43_radio_write16(dev, 0x005A, 0x0070);
1386 b43_radio_write16(dev, 0x005B, 0x007B);
1387 b43_radio_write16(dev, 0x005C, 0x00B0);
1389 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0007);
1391 b43_radio_selectchannel(dev, old_channel, 0);
1393 b43_phy_write(dev, 0x0014, 0x0080);
1394 b43_phy_write(dev, 0x0032, 0x00CA);
1395 b43_phy_write(dev, 0x002A, 0x88A3);
1397 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1399 if (phy->radio_ver == 0x2050)
1400 b43_radio_write16(dev, 0x005D, 0x000D);
1402 b43_write16(dev, 0x03E4, (b43_read16(dev, 0x03E4) & 0xFFC0) | 0x0004);
1405 static void b43_phy_initb6(struct b43_wldev *dev)
1407 struct b43_phy *phy = &dev->phy;
1411 b43_phy_write(dev, 0x003E, 0x817A);
1412 b43_radio_write16(dev, 0x007A,
1413 (b43_radio_read16(dev, 0x007A) | 0x0058));
1414 if (phy->radio_rev == 4 || phy->radio_rev == 5) {
1415 b43_radio_write16(dev, 0x51, 0x37);
1416 b43_radio_write16(dev, 0x52, 0x70);
1417 b43_radio_write16(dev, 0x53, 0xB3);
1418 b43_radio_write16(dev, 0x54, 0x9B);
1419 b43_radio_write16(dev, 0x5A, 0x88);
1420 b43_radio_write16(dev, 0x5B, 0x88);
1421 b43_radio_write16(dev, 0x5D, 0x88);
1422 b43_radio_write16(dev, 0x5E, 0x88);
1423 b43_radio_write16(dev, 0x7D, 0x88);
1424 b43_hf_write(dev, b43_hf_read(dev)
1425 | B43_HF_TSSIRPSMW);
1427 B43_WARN_ON(phy->radio_rev == 6 || phy->radio_rev == 7); /* We had code for these revs here... */
1428 if (phy->radio_rev == 8) {
1429 b43_radio_write16(dev, 0x51, 0);
1430 b43_radio_write16(dev, 0x52, 0x40);
1431 b43_radio_write16(dev, 0x53, 0xB7);
1432 b43_radio_write16(dev, 0x54, 0x98);
1433 b43_radio_write16(dev, 0x5A, 0x88);
1434 b43_radio_write16(dev, 0x5B, 0x6B);
1435 b43_radio_write16(dev, 0x5C, 0x0F);
1436 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_ALTIQ) {
1437 b43_radio_write16(dev, 0x5D, 0xFA);
1438 b43_radio_write16(dev, 0x5E, 0xD8);
1440 b43_radio_write16(dev, 0x5D, 0xF5);
1441 b43_radio_write16(dev, 0x5E, 0xB8);
1443 b43_radio_write16(dev, 0x0073, 0x0003);
1444 b43_radio_write16(dev, 0x007D, 0x00A8);
1445 b43_radio_write16(dev, 0x007C, 0x0001);
1446 b43_radio_write16(dev, 0x007E, 0x0008);
1449 for (offset = 0x0088; offset < 0x0098; offset++) {
1450 b43_phy_write(dev, offset, val);
1454 for (offset = 0x0098; offset < 0x00A8; offset++) {
1455 b43_phy_write(dev, offset, val);
1459 for (offset = 0x00A8; offset < 0x00C8; offset++) {
1460 b43_phy_write(dev, offset, (val & 0x3F3F));
1463 if (phy->type == B43_PHYTYPE_G) {
1464 b43_radio_write16(dev, 0x007A,
1465 b43_radio_read16(dev, 0x007A) | 0x0020);
1466 b43_radio_write16(dev, 0x0051,
1467 b43_radio_read16(dev, 0x0051) | 0x0004);
1468 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1469 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1470 b43_phy_write(dev, 0x5B, 0);
1471 b43_phy_write(dev, 0x5C, 0);
1474 old_channel = phy->channel;
1475 if (old_channel >= 8)
1476 b43_radio_selectchannel(dev, 1, 0);
1478 b43_radio_selectchannel(dev, 13, 0);
1480 b43_radio_write16(dev, 0x0050, 0x0020);
1481 b43_radio_write16(dev, 0x0050, 0x0023);
1483 if (phy->radio_rev < 6 || phy->radio_rev == 8) {
1484 b43_radio_write16(dev, 0x7C, (b43_radio_read16(dev, 0x7C)
1486 b43_radio_write16(dev, 0x50, 0x20);
1488 if (phy->radio_rev <= 2) {
1489 b43_radio_write16(dev, 0x7C, 0x20);
1490 b43_radio_write16(dev, 0x5A, 0x70);
1491 b43_radio_write16(dev, 0x5B, 0x7B);
1492 b43_radio_write16(dev, 0x5C, 0xB0);
1494 b43_radio_write16(dev, 0x007A,
1495 (b43_radio_read16(dev, 0x007A) & 0x00F8) | 0x0007);
1497 b43_radio_selectchannel(dev, old_channel, 0);
1499 b43_phy_write(dev, 0x0014, 0x0200);
1500 if (phy->radio_rev >= 6)
1501 b43_phy_write(dev, 0x2A, 0x88C2);
1503 b43_phy_write(dev, 0x2A, 0x8AC0);
1504 b43_phy_write(dev, 0x0038, 0x0668);
1505 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1506 if (phy->radio_rev <= 5) {
1507 b43_phy_write(dev, 0x5D, (b43_phy_read(dev, 0x5D)
1508 & 0xFF80) | 0x0003);
1510 if (phy->radio_rev <= 2)
1511 b43_radio_write16(dev, 0x005D, 0x000D);
1513 if (phy->analog == 4) {
1514 b43_write16(dev, 0x3E4, 9);
1515 b43_phy_write(dev, 0x61, b43_phy_read(dev, 0x61)
1518 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0)
1521 if (phy->type == B43_PHYTYPE_B) {
1522 b43_write16(dev, 0x03E6, 0x8140);
1523 b43_phy_write(dev, 0x0016, 0x0410);
1524 b43_phy_write(dev, 0x0017, 0x0820);
1525 b43_phy_write(dev, 0x0062, 0x0007);
1526 b43_radio_init2050(dev);
1527 b43_lo_g_measure(dev);
1528 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI) {
1529 b43_calc_nrssi_slope(dev);
1530 b43_calc_nrssi_threshold(dev);
1532 b43_phy_init_pctl(dev);
1533 } else if (phy->type == B43_PHYTYPE_G)
1534 b43_write16(dev, 0x03E6, 0x0);
1537 static void b43_calc_loopback_gain(struct b43_wldev *dev)
1539 struct b43_phy *phy = &dev->phy;
1540 u16 backup_phy[16] = { 0 };
1541 u16 backup_radio[3];
1543 u16 i, j, loop_i_max;
1545 u16 loop1_outer_done, loop1_inner_done;
1547 backup_phy[0] = b43_phy_read(dev, B43_PHY_CRS0);
1548 backup_phy[1] = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
1549 backup_phy[2] = b43_phy_read(dev, B43_PHY_RFOVER);
1550 backup_phy[3] = b43_phy_read(dev, B43_PHY_RFOVERVAL);
1551 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1552 backup_phy[4] = b43_phy_read(dev, B43_PHY_ANALOGOVER);
1553 backup_phy[5] = b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
1555 backup_phy[6] = b43_phy_read(dev, B43_PHY_BASE(0x5A));
1556 backup_phy[7] = b43_phy_read(dev, B43_PHY_BASE(0x59));
1557 backup_phy[8] = b43_phy_read(dev, B43_PHY_BASE(0x58));
1558 backup_phy[9] = b43_phy_read(dev, B43_PHY_BASE(0x0A));
1559 backup_phy[10] = b43_phy_read(dev, B43_PHY_BASE(0x03));
1560 backup_phy[11] = b43_phy_read(dev, B43_PHY_LO_MASK);
1561 backup_phy[12] = b43_phy_read(dev, B43_PHY_LO_CTL);
1562 backup_phy[13] = b43_phy_read(dev, B43_PHY_BASE(0x2B));
1563 backup_phy[14] = b43_phy_read(dev, B43_PHY_PGACTL);
1564 backup_phy[15] = b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
1565 backup_bband = phy->bbatt.att;
1566 backup_radio[0] = b43_radio_read16(dev, 0x52);
1567 backup_radio[1] = b43_radio_read16(dev, 0x43);
1568 backup_radio[2] = b43_radio_read16(dev, 0x7A);
1570 b43_phy_write(dev, B43_PHY_CRS0,
1571 b43_phy_read(dev, B43_PHY_CRS0) & 0x3FFF);
1572 b43_phy_write(dev, B43_PHY_CCKBBANDCFG,
1573 b43_phy_read(dev, B43_PHY_CCKBBANDCFG) | 0x8000);
1574 b43_phy_write(dev, B43_PHY_RFOVER,
1575 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0002);
1576 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1577 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFD);
1578 b43_phy_write(dev, B43_PHY_RFOVER,
1579 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0001);
1580 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1581 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFE);
1582 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1583 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1584 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0001);
1585 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1587 B43_PHY_ANALOGOVERVAL) & 0xFFFE);
1588 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1589 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0002);
1590 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1592 B43_PHY_ANALOGOVERVAL) & 0xFFFD);
1594 b43_phy_write(dev, B43_PHY_RFOVER,
1595 b43_phy_read(dev, B43_PHY_RFOVER) | 0x000C);
1596 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1597 b43_phy_read(dev, B43_PHY_RFOVERVAL) | 0x000C);
1598 b43_phy_write(dev, B43_PHY_RFOVER,
1599 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0030);
1600 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1601 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1604 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0780);
1605 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
1606 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
1608 b43_phy_write(dev, B43_PHY_BASE(0x0A),
1609 b43_phy_read(dev, B43_PHY_BASE(0x0A)) | 0x2000);
1610 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1611 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1612 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0004);
1613 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1615 B43_PHY_ANALOGOVERVAL) & 0xFFFB);
1617 b43_phy_write(dev, B43_PHY_BASE(0x03),
1618 (b43_phy_read(dev, B43_PHY_BASE(0x03))
1621 if (phy->radio_rev == 8) {
1622 b43_radio_write16(dev, 0x43, 0x000F);
1624 b43_radio_write16(dev, 0x52, 0);
1625 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
1628 b43_phy_set_baseband_attenuation(dev, 11);
1631 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
1633 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
1634 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
1636 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1637 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1639 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1640 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1643 b43_phy_write(dev, B43_PHY_RFOVER,
1644 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0100);
1645 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1646 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xCFFF);
1648 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_EXTLNA) {
1649 if (phy->rev >= 7) {
1650 b43_phy_write(dev, B43_PHY_RFOVER,
1651 b43_phy_read(dev, B43_PHY_RFOVER)
1653 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1654 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1658 b43_radio_write16(dev, 0x7A, b43_radio_read16(dev, 0x7A)
1662 loop_i_max = (phy->radio_rev == 8) ? 15 : 9;
1663 for (i = 0; i < loop_i_max; i++) {
1664 for (j = 0; j < 16; j++) {
1665 b43_radio_write16(dev, 0x43, i);
1666 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1667 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1668 & 0xF0FF) | (j << 8));
1669 b43_phy_write(dev, B43_PHY_PGACTL,
1670 (b43_phy_read(dev, B43_PHY_PGACTL)
1671 & 0x0FFF) | 0xA000);
1672 b43_phy_write(dev, B43_PHY_PGACTL,
1673 b43_phy_read(dev, B43_PHY_PGACTL)
1676 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1681 loop1_outer_done = i;
1682 loop1_inner_done = j;
1684 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1685 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1688 for (j = j - 8; j < 16; j++) {
1689 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1690 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1691 & 0xF0FF) | (j << 8));
1692 b43_phy_write(dev, B43_PHY_PGACTL,
1693 (b43_phy_read(dev, B43_PHY_PGACTL)
1694 & 0x0FFF) | 0xA000);
1695 b43_phy_write(dev, B43_PHY_PGACTL,
1696 b43_phy_read(dev, B43_PHY_PGACTL)
1700 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1707 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1708 b43_phy_write(dev, B43_PHY_ANALOGOVER, backup_phy[4]);
1709 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, backup_phy[5]);
1711 b43_phy_write(dev, B43_PHY_BASE(0x5A), backup_phy[6]);
1712 b43_phy_write(dev, B43_PHY_BASE(0x59), backup_phy[7]);
1713 b43_phy_write(dev, B43_PHY_BASE(0x58), backup_phy[8]);
1714 b43_phy_write(dev, B43_PHY_BASE(0x0A), backup_phy[9]);
1715 b43_phy_write(dev, B43_PHY_BASE(0x03), backup_phy[10]);
1716 b43_phy_write(dev, B43_PHY_LO_MASK, backup_phy[11]);
1717 b43_phy_write(dev, B43_PHY_LO_CTL, backup_phy[12]);
1718 b43_phy_write(dev, B43_PHY_BASE(0x2B), backup_phy[13]);
1719 b43_phy_write(dev, B43_PHY_PGACTL, backup_phy[14]);
1721 b43_phy_set_baseband_attenuation(dev, backup_bband);
1723 b43_radio_write16(dev, 0x52, backup_radio[0]);
1724 b43_radio_write16(dev, 0x43, backup_radio[1]);
1725 b43_radio_write16(dev, 0x7A, backup_radio[2]);
1727 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2] | 0x0003);
1729 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2]);
1730 b43_phy_write(dev, B43_PHY_RFOVERVAL, backup_phy[3]);
1731 b43_phy_write(dev, B43_PHY_CRS0, backup_phy[0]);
1732 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, backup_phy[1]);
1735 ((loop1_inner_done * 6) - (loop1_outer_done * 4)) - 11;
1736 phy->trsw_rx_gain = trsw_rx * 2;
1739 static void b43_phy_initg(struct b43_wldev *dev)
1741 struct b43_phy *phy = &dev->phy;
1745 b43_phy_initb5(dev);
1747 b43_phy_initb6(dev);
1749 if (phy->rev >= 2 || phy->gmode)
1752 if (phy->rev >= 2) {
1753 b43_phy_write(dev, B43_PHY_ANALOGOVER, 0);
1754 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, 0);
1756 if (phy->rev == 2) {
1757 b43_phy_write(dev, B43_PHY_RFOVER, 0);
1758 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1761 b43_phy_write(dev, B43_PHY_RFOVER, 0x400);
1762 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1764 if (phy->gmode || phy->rev >= 2) {
1765 tmp = b43_phy_read(dev, B43_PHY_VERSION_OFDM);
1766 tmp &= B43_PHYVER_VERSION;
1767 if (tmp == 3 || tmp == 5) {
1768 b43_phy_write(dev, B43_PHY_OFDM(0xC2), 0x1816);
1769 b43_phy_write(dev, B43_PHY_OFDM(0xC3), 0x8006);
1772 b43_phy_write(dev, B43_PHY_OFDM(0xCC),
1773 (b43_phy_read(dev, B43_PHY_OFDM(0xCC))
1774 & 0x00FF) | 0x1F00);
1777 if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2)
1778 b43_phy_write(dev, B43_PHY_OFDM(0x7E), 0x78);
1779 if (phy->radio_rev == 8) {
1780 b43_phy_write(dev, B43_PHY_EXTG(0x01),
1781 b43_phy_read(dev, B43_PHY_EXTG(0x01))
1783 b43_phy_write(dev, B43_PHY_OFDM(0x3E),
1784 b43_phy_read(dev, B43_PHY_OFDM(0x3E))
1787 if (has_loopback_gain(phy))
1788 b43_calc_loopback_gain(dev);
1790 if (phy->radio_rev != 8) {
1791 if (phy->initval == 0xFFFF)
1792 phy->initval = b43_radio_init2050(dev);
1794 b43_radio_write16(dev, 0x0078, phy->initval);
1796 if (phy->lo_control->tx_bias == 0xFF) {
1797 b43_lo_g_measure(dev);
1799 if (has_tx_magnification(phy)) {
1800 b43_radio_write16(dev, 0x52,
1801 (b43_radio_read16(dev, 0x52) & 0xFF00)
1802 | phy->lo_control->tx_bias | phy->
1803 lo_control->tx_magn);
1805 b43_radio_write16(dev, 0x52,
1806 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1807 | phy->lo_control->tx_bias);
1809 if (phy->rev >= 6) {
1810 b43_phy_write(dev, B43_PHY_BASE(0x36),
1811 (b43_phy_read(dev, B43_PHY_BASE(0x36))
1812 & 0x0FFF) | (phy->lo_control->
1815 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_PACTRL)
1816 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x8075);
1818 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x807F);
1820 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x101);
1822 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x202);
1824 if (phy->gmode || phy->rev >= 2) {
1825 b43_lo_g_adjust(dev);
1826 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
1829 if (!(dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI)) {
1830 /* The specs state to update the NRSSI LT with
1831 * the value 0x7FFFFFFF here. I think that is some weird
1832 * compiler optimization in the original driver.
1833 * Essentially, what we do here is resetting all NRSSI LT
1834 * entries to -32 (see the limit_value() in nrssi_hw_update())
1836 b43_nrssi_hw_update(dev, 0xFFFF); //FIXME?
1837 b43_calc_nrssi_threshold(dev);
1838 } else if (phy->gmode || phy->rev >= 2) {
1839 if (phy->nrssi[0] == -1000) {
1840 B43_WARN_ON(phy->nrssi[1] != -1000);
1841 b43_calc_nrssi_slope(dev);
1843 b43_calc_nrssi_threshold(dev);
1845 if (phy->radio_rev == 8)
1846 b43_phy_write(dev, B43_PHY_EXTG(0x05), 0x3230);
1847 b43_phy_init_pctl(dev);
1848 /* FIXME: The spec says in the following if, the 0 should be replaced
1849 'if OFDM may not be used in the current locale'
1850 but OFDM is legal everywhere */
1851 if ((dev->dev->bus->chip_id == 0x4306
1852 && dev->dev->bus->chip_package == 2) || 0) {
1853 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
1855 b43_phy_write(dev, B43_PHY_OFDM(0xC3),
1856 b43_phy_read(dev, B43_PHY_OFDM(0xC3))
1861 /* Set the baseband attenuation value on chip. */
1862 void b43_phy_set_baseband_attenuation(struct b43_wldev *dev,
1863 u16 baseband_attenuation)
1865 struct b43_phy *phy = &dev->phy;
1867 if (phy->analog == 0) {
1868 b43_write16(dev, B43_MMIO_PHY0, (b43_read16(dev, B43_MMIO_PHY0)
1870 baseband_attenuation);
1871 } else if (phy->analog > 1) {
1872 b43_phy_write(dev, B43_PHY_DACCTL,
1873 (b43_phy_read(dev, B43_PHY_DACCTL)
1874 & 0xFFC3) | (baseband_attenuation << 2));
1876 b43_phy_write(dev, B43_PHY_DACCTL,
1877 (b43_phy_read(dev, B43_PHY_DACCTL)
1878 & 0xFF87) | (baseband_attenuation << 3));
1882 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1883 * This function converts a TSSI value to dBm in Q5.2
1885 static s8 b43_phy_estimate_power_out(struct b43_wldev *dev, s8 tssi)
1887 struct b43_phy *phy = &dev->phy;
1891 tmp = (phy->tgt_idle_tssi - phy->cur_idle_tssi + tssi);
1893 switch (phy->type) {
1896 tmp = limit_value(tmp, 0x00, 0xFF);
1897 dbm = phy->tssi2dbm[tmp];
1898 //TODO: There's a FIXME on the specs
1902 tmp = limit_value(tmp, 0x00, 0x3F);
1903 dbm = phy->tssi2dbm[tmp];
1912 void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
1913 int *_bbatt, int *_rfatt)
1915 int rfatt = *_rfatt;
1916 int bbatt = *_bbatt;
1917 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
1919 /* Get baseband and radio attenuation values into their permitted ranges.
1920 * Radio attenuation affects power level 4 times as much as baseband. */
1922 /* Range constants */
1923 const int rf_min = lo->rfatt_list.min_val;
1924 const int rf_max = lo->rfatt_list.max_val;
1925 const int bb_min = lo->bbatt_list.min_val;
1926 const int bb_max = lo->bbatt_list.max_val;
1929 if (rfatt > rf_max && bbatt > bb_max - 4)
1930 break; /* Can not get it into ranges */
1931 if (rfatt < rf_min && bbatt < bb_min + 4)
1932 break; /* Can not get it into ranges */
1933 if (bbatt > bb_max && rfatt > rf_max - 1)
1934 break; /* Can not get it into ranges */
1935 if (bbatt < bb_min && rfatt < rf_min + 1)
1936 break; /* Can not get it into ranges */
1938 if (bbatt > bb_max) {
1943 if (bbatt < bb_min) {
1948 if (rfatt > rf_max) {
1953 if (rfatt < rf_min) {
1961 *_rfatt = limit_value(rfatt, rf_min, rf_max);
1962 *_bbatt = limit_value(bbatt, bb_min, bb_max);
1965 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1966 void b43_phy_xmitpower(struct b43_wldev *dev)
1968 struct ssb_bus *bus = dev->dev->bus;
1969 struct b43_phy *phy = &dev->phy;
1971 if (phy->cur_idle_tssi == 0)
1973 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1974 (bus->boardinfo.type == SSB_BOARD_BU4306))
1976 #ifdef CONFIG_B43_DEBUG
1977 if (phy->manual_txpower_control)
1981 switch (phy->type) {
1982 case B43_PHYTYPE_A:{
1984 //TODO: Nothing for A PHYs yet :-/
1989 case B43_PHYTYPE_G:{
1994 int desired_pwr, estimated_pwr, pwr_adjust;
1995 int rfatt_delta, bbatt_delta;
1998 unsigned long phylock_flags;
2000 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x0058);
2001 v0 = (s8) (tmp & 0x00FF);
2002 v1 = (s8) ((tmp & 0xFF00) >> 8);
2003 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x005A);
2004 v2 = (s8) (tmp & 0x00FF);
2005 v3 = (s8) ((tmp & 0xFF00) >> 8);
2008 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
2011 b43_shm_read16(dev, B43_SHM_SHARED, 0x0070);
2012 v0 = (s8) (tmp & 0x00FF);
2013 v1 = (s8) ((tmp & 0xFF00) >> 8);
2015 b43_shm_read16(dev, B43_SHM_SHARED, 0x0072);
2016 v2 = (s8) (tmp & 0x00FF);
2017 v3 = (s8) ((tmp & 0xFF00) >> 8);
2018 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
2021 v0 = (v0 + 0x20) & 0x3F;
2022 v1 = (v1 + 0x20) & 0x3F;
2023 v2 = (v2 + 0x20) & 0x3F;
2024 v3 = (v3 + 0x20) & 0x3F;
2027 b43_shm_clear_tssi(dev);
2029 average = (v0 + v1 + v2 + v3 + 2) / 4;
2032 && (b43_shm_read16(dev, B43_SHM_SHARED, 0x005E) &
2037 b43_phy_estimate_power_out(dev, average);
2039 max_pwr = dev->dev->bus->sprom.r1.maxpwr_bg;
2040 if ((dev->dev->bus->sprom.r1.
2041 boardflags_lo & B43_BFL_PACTRL)
2042 && (phy->type == B43_PHYTYPE_G))
2044 if (unlikely(max_pwr <= 0)) {
2046 "Invalid max-TX-power value in SPROM.\n");
2047 max_pwr = 60; /* fake it */
2048 dev->dev->bus->sprom.r1.maxpwr_bg = max_pwr;
2052 max_pwr = min(REG - dev->dev->bus->sprom.antennagain_bgphy - 0x6, max_pwr)
2053 where REG is the max power as per the regulatory domain
2056 /* Get desired power (in Q5.2) */
2057 desired_pwr = INT_TO_Q52(phy->power_level);
2058 /* And limit it. max_pwr already is Q5.2 */
2059 desired_pwr = limit_value(desired_pwr, 0, max_pwr);
2060 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
2062 "Current TX power output: " Q52_FMT
2063 " dBm, " "Desired TX power output: "
2064 Q52_FMT " dBm\n", Q52_ARG(estimated_pwr),
2065 Q52_ARG(desired_pwr));
2068 /* Calculate the adjustment delta. */
2069 pwr_adjust = desired_pwr - estimated_pwr;
2071 /* RF attenuation delta. */
2072 rfatt_delta = ((pwr_adjust + 7) / 8);
2073 /* Lower attenuation => Bigger power output. Negate it. */
2074 rfatt_delta = -rfatt_delta;
2076 /* Baseband attenuation delta. */
2077 bbatt_delta = pwr_adjust / 2;
2078 /* Lower attenuation => Bigger power output. Negate it. */
2079 bbatt_delta = -bbatt_delta;
2080 /* RF att affects power level 4 times as much as
2081 * Baseband attennuation. Subtract it. */
2082 bbatt_delta -= 4 * rfatt_delta;
2084 /* So do we finally need to adjust something? */
2085 if ((rfatt_delta == 0) && (bbatt_delta == 0)) {
2086 b43_lo_g_ctl_mark_cur_used(dev);
2090 /* Calculate the new attenuation values. */
2091 bbatt = phy->bbatt.att;
2092 bbatt += bbatt_delta;
2093 rfatt = phy->rfatt.att;
2094 rfatt += rfatt_delta;
2096 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
2097 tx_control = phy->tx_control;
2098 if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 2)) {
2100 if (tx_control == 0) {
2106 } else if (dev->dev->bus->sprom.r1.
2109 bbatt += 4 * (rfatt - 2);
2112 } else if (rfatt > 4 && tx_control) {
2123 /* Save the control values */
2124 phy->tx_control = tx_control;
2125 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
2126 phy->rfatt.att = rfatt;
2127 phy->bbatt.att = bbatt;
2129 /* Adjust the hardware */
2130 b43_phy_lock(dev, phylock_flags);
2131 b43_radio_lock(dev);
2132 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt,
2134 b43_lo_g_ctl_mark_cur_used(dev);
2135 b43_radio_unlock(dev);
2136 b43_phy_unlock(dev, phylock_flags);
2144 static inline s32 b43_tssi2dbm_ad(s32 num, s32 den)
2149 return (num + den / 2) / den;
2153 s8 b43_tssi2dbm_entry(s8 entry[], u8 index, s16 pab0, s16 pab1, s16 pab2)
2155 s32 m1, m2, f = 256, q, delta;
2158 m1 = b43_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2159 m2 = max(b43_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2163 q = b43_tssi2dbm_ad(f * 4096 -
2164 b43_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2168 } while (delta >= 2);
2169 entry[index] = limit_value(b43_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2173 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2174 int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev)
2176 struct b43_phy *phy = &dev->phy;
2177 s16 pab0, pab1, pab2;
2181 if (phy->type == B43_PHYTYPE_A) {
2182 pab0 = (s16) (dev->dev->bus->sprom.r1.pa1b0);
2183 pab1 = (s16) (dev->dev->bus->sprom.r1.pa1b1);
2184 pab2 = (s16) (dev->dev->bus->sprom.r1.pa1b2);
2186 pab0 = (s16) (dev->dev->bus->sprom.r1.pa0b0);
2187 pab1 = (s16) (dev->dev->bus->sprom.r1.pa0b1);
2188 pab2 = (s16) (dev->dev->bus->sprom.r1.pa0b2);
2191 if ((dev->dev->bus->chip_id == 0x4301) && (phy->radio_ver != 0x2050)) {
2192 phy->tgt_idle_tssi = 0x34;
2193 phy->tssi2dbm = b43_tssi2dbm_b_table;
2197 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2198 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2199 /* The pabX values are set in SPROM. Use them. */
2200 if (phy->type == B43_PHYTYPE_A) {
2201 if ((s8) dev->dev->bus->sprom.r1.itssi_a != 0 &&
2202 (s8) dev->dev->bus->sprom.r1.itssi_a != -1)
2203 phy->tgt_idle_tssi =
2204 (s8) (dev->dev->bus->sprom.r1.itssi_a);
2206 phy->tgt_idle_tssi = 62;
2208 if ((s8) dev->dev->bus->sprom.r1.itssi_bg != 0 &&
2209 (s8) dev->dev->bus->sprom.r1.itssi_bg != -1)
2210 phy->tgt_idle_tssi =
2211 (s8) (dev->dev->bus->sprom.r1.itssi_bg);
2213 phy->tgt_idle_tssi = 62;
2215 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2216 if (dyn_tssi2dbm == NULL) {
2217 b43err(dev->wl, "Could not allocate memory "
2218 "for tssi2dbm table\n");
2221 for (idx = 0; idx < 64; idx++)
2222 if (b43_tssi2dbm_entry
2223 (dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2224 phy->tssi2dbm = NULL;
2225 b43err(dev->wl, "Could not generate "
2226 "tssi2dBm table\n");
2227 kfree(dyn_tssi2dbm);
2230 phy->tssi2dbm = dyn_tssi2dbm;
2231 phy->dyn_tssi_tbl = 1;
2233 /* pabX values not set in SPROM. */
2234 switch (phy->type) {
2236 /* APHY needs a generated table. */
2237 phy->tssi2dbm = NULL;
2238 b43err(dev->wl, "Could not generate tssi2dBm "
2239 "table (wrong SPROM info)!\n");
2242 phy->tgt_idle_tssi = 0x34;
2243 phy->tssi2dbm = b43_tssi2dbm_b_table;
2246 phy->tgt_idle_tssi = 0x34;
2247 phy->tssi2dbm = b43_tssi2dbm_g_table;
2255 int b43_phy_init(struct b43_wldev *dev)
2257 struct b43_phy *phy = &dev->phy;
2260 switch (phy->type) {
2262 if (phy->rev == 2 || phy->rev == 3) {
2270 b43_phy_initb2(dev);
2274 b43_phy_initb4(dev);
2278 b43_phy_initb5(dev);
2282 b43_phy_initb6(dev);
2293 b43err(dev->wl, "Unknown PHYTYPE found\n");
2298 void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2300 struct b43_phy *phy = &dev->phy;
2305 if (antenna == B43_ANTENNA_AUTO0 || antenna == B43_ANTENNA_AUTO1)
2308 hf = b43_hf_read(dev);
2309 hf &= ~B43_HF_ANTDIVHELP;
2310 b43_hf_write(dev, hf);
2312 switch (phy->type) {
2315 tmp = b43_phy_read(dev, B43_PHY_BBANDCFG);
2316 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2317 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2318 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2319 b43_phy_write(dev, B43_PHY_BBANDCFG, tmp);
2322 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2323 if (antenna == B43_ANTENNA_AUTO0)
2324 tmp &= ~B43_PHY_ANTDWELL_AUTODIV1;
2326 tmp |= B43_PHY_ANTDWELL_AUTODIV1;
2327 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2329 if (phy->type == B43_PHYTYPE_G) {
2330 tmp = b43_phy_read(dev, B43_PHY_ANTWRSETT);
2332 tmp |= B43_PHY_ANTWRSETT_ARXDIV;
2334 tmp &= ~B43_PHY_ANTWRSETT_ARXDIV;
2335 b43_phy_write(dev, B43_PHY_ANTWRSETT, tmp);
2336 if (phy->rev >= 2) {
2337 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2338 tmp |= B43_PHY_OFDM61_10;
2339 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2342 b43_phy_read(dev, B43_PHY_DIVSRCHGAINBACK);
2343 tmp = (tmp & 0xFF00) | 0x15;
2344 b43_phy_write(dev, B43_PHY_DIVSRCHGAINBACK,
2347 if (phy->rev == 2) {
2348 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2353 B43_PHY_ADIVRELATED);
2354 tmp = (tmp & 0xFF00) | 8;
2355 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2360 b43_phy_write(dev, B43_PHY_OFDM9B, 0xDC);
2363 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2364 tmp = (tmp & 0xFF00) | 0x24;
2365 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2367 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2369 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2370 if (phy->analog == 3) {
2371 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2373 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2376 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2380 B43_PHY_ADIVRELATED);
2381 tmp = (tmp & 0xFF00) | 8;
2382 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2389 tmp = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
2390 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2391 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2392 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2393 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, tmp);
2399 hf |= B43_HF_ANTDIVHELP;
2400 b43_hf_write(dev, hf);
2403 /* Get the freq, as it has to be written to the device. */
2404 static inline u16 channel2freq_bg(u8 channel)
2406 B43_WARN_ON(!(channel >= 1 && channel <= 14));
2408 return b43_radio_channel_codes_bg[channel - 1];
2411 /* Get the freq, as it has to be written to the device. */
2412 static inline u16 channel2freq_a(u8 channel)
2414 B43_WARN_ON(channel > 200);
2416 return (5000 + 5 * channel);
2419 void b43_radio_lock(struct b43_wldev *dev)
2423 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2424 macctl |= B43_MACCTL_RADIOLOCK;
2425 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2426 /* Commit the write and wait for the device
2427 * to exit any radio register access. */
2428 b43_read32(dev, B43_MMIO_MACCTL);
2432 void b43_radio_unlock(struct b43_wldev *dev)
2436 /* Commit any write */
2437 b43_read16(dev, B43_MMIO_PHY_VER);
2439 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2440 macctl &= ~B43_MACCTL_RADIOLOCK;
2441 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2444 u16 b43_radio_read16(struct b43_wldev *dev, u16 offset)
2446 struct b43_phy *phy = &dev->phy;
2448 switch (phy->type) {
2453 if (phy->radio_ver == 0x2053) {
2456 else if (offset < 0x80)
2458 } else if (phy->radio_ver == 0x2050) {
2468 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2469 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
2472 void b43_radio_write16(struct b43_wldev *dev, u16 offset, u16 val)
2474 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2476 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, val);
2479 static void b43_set_all_gains(struct b43_wldev *dev,
2480 s16 first, s16 second, s16 third)
2482 struct b43_phy *phy = &dev->phy;
2484 u16 start = 0x08, end = 0x18;
2488 if (phy->rev <= 1) {
2493 table = B43_OFDMTAB_GAINX;
2495 table = B43_OFDMTAB_GAINX_R1;
2496 for (i = 0; i < 4; i++)
2497 b43_ofdmtab_write16(dev, table, i, first);
2499 for (i = start; i < end; i++)
2500 b43_ofdmtab_write16(dev, table, i, second);
2503 tmp = ((u16) third << 14) | ((u16) third << 6);
2504 b43_phy_write(dev, 0x04A0,
2505 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | tmp);
2506 b43_phy_write(dev, 0x04A1,
2507 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | tmp);
2508 b43_phy_write(dev, 0x04A2,
2509 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | tmp);
2511 b43_dummy_transmission(dev);
2514 static void b43_set_original_gains(struct b43_wldev *dev)
2516 struct b43_phy *phy = &dev->phy;
2519 u16 start = 0x0008, end = 0x0018;
2521 if (phy->rev <= 1) {
2526 table = B43_OFDMTAB_GAINX;
2528 table = B43_OFDMTAB_GAINX_R1;
2529 for (i = 0; i < 4; i++) {
2531 tmp |= (i & 0x0001) << 1;
2532 tmp |= (i & 0x0002) >> 1;
2534 b43_ofdmtab_write16(dev, table, i, tmp);
2537 for (i = start; i < end; i++)
2538 b43_ofdmtab_write16(dev, table, i, i - start);
2540 b43_phy_write(dev, 0x04A0,
2541 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | 0x4040);
2542 b43_phy_write(dev, 0x04A1,
2543 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | 0x4040);
2544 b43_phy_write(dev, 0x04A2,
2545 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | 0x4000);
2546 b43_dummy_transmission(dev);
2549 /* Synthetic PU workaround */
2550 static void b43_synth_pu_workaround(struct b43_wldev *dev, u8 channel)
2552 struct b43_phy *phy = &dev->phy;
2556 if (phy->radio_ver != 0x2050 || phy->radio_rev >= 6) {
2557 /* We do not need the workaround. */
2561 if (channel <= 10) {
2562 b43_write16(dev, B43_MMIO_CHANNEL,
2563 channel2freq_bg(channel + 4));
2565 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(1));
2568 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
2571 u8 b43_radio_aci_detect(struct b43_wldev *dev, u8 channel)
2573 struct b43_phy *phy = &dev->phy;
2575 u16 saved, rssi, temp;
2578 saved = b43_phy_read(dev, 0x0403);
2579 b43_radio_selectchannel(dev, channel, 0);
2580 b43_phy_write(dev, 0x0403, (saved & 0xFFF8) | 5);
2581 if (phy->aci_hw_rssi)
2582 rssi = b43_phy_read(dev, 0x048A) & 0x3F;
2584 rssi = saved & 0x3F;
2585 /* clamp temp to signed 5bit */
2588 for (i = 0; i < 100; i++) {
2589 temp = (b43_phy_read(dev, 0x047F) >> 8) & 0x3F;
2597 b43_phy_write(dev, 0x0403, saved);
2602 u8 b43_radio_aci_scan(struct b43_wldev * dev)
2604 struct b43_phy *phy = &dev->phy;
2606 unsigned int channel = phy->channel;
2607 unsigned int i, j, start, end;
2608 unsigned long phylock_flags;
2610 if (!((phy->type == B43_PHYTYPE_G) && (phy->rev > 0)))
2613 b43_phy_lock(dev, phylock_flags);
2614 b43_radio_lock(dev);
2615 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2616 b43_phy_write(dev, B43_PHY_G_CRS,
2617 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2618 b43_set_all_gains(dev, 3, 8, 1);
2620 start = (channel - 5 > 0) ? channel - 5 : 1;
2621 end = (channel + 5 < 14) ? channel + 5 : 13;
2623 for (i = start; i <= end; i++) {
2624 if (abs(channel - i) > 2)
2625 ret[i - 1] = b43_radio_aci_detect(dev, i);
2627 b43_radio_selectchannel(dev, channel, 0);
2628 b43_phy_write(dev, 0x0802,
2629 (b43_phy_read(dev, 0x0802) & 0xFFFC) | 0x0003);
2630 b43_phy_write(dev, 0x0403, b43_phy_read(dev, 0x0403) & 0xFFF8);
2631 b43_phy_write(dev, B43_PHY_G_CRS,
2632 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2633 b43_set_original_gains(dev);
2634 for (i = 0; i < 13; i++) {
2637 end = (i + 5 < 13) ? i + 5 : 13;
2638 for (j = i; j < end; j++)
2641 b43_radio_unlock(dev);
2642 b43_phy_unlock(dev, phylock_flags);
2644 return ret[channel - 1];
2647 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2648 void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val)
2650 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2652 b43_phy_write(dev, B43_PHY_NRSSILT_DATA, (u16) val);
2655 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2656 s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset)
2660 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2661 val = b43_phy_read(dev, B43_PHY_NRSSILT_DATA);
2666 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2667 void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val)
2672 for (i = 0; i < 64; i++) {
2673 tmp = b43_nrssi_hw_read(dev, i);
2675 tmp = limit_value(tmp, -32, 31);
2676 b43_nrssi_hw_write(dev, i, tmp);
2680 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2681 void b43_nrssi_mem_update(struct b43_wldev *dev)
2683 struct b43_phy *phy = &dev->phy;
2687 delta = 0x1F - phy->nrssi[0];
2688 for (i = 0; i < 64; i++) {
2689 tmp = (i - delta) * phy->nrssislope;
2692 tmp = limit_value(tmp, 0, 0x3F);
2693 phy->nrssi_lt[i] = tmp;
2697 static void b43_calc_nrssi_offset(struct b43_wldev *dev)
2699 struct b43_phy *phy = &dev->phy;
2700 u16 backup[20] = { 0 };
2705 backup[0] = b43_phy_read(dev, 0x0001);
2706 backup[1] = b43_phy_read(dev, 0x0811);
2707 backup[2] = b43_phy_read(dev, 0x0812);
2708 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2709 backup[3] = b43_phy_read(dev, 0x0814);
2710 backup[4] = b43_phy_read(dev, 0x0815);
2712 backup[5] = b43_phy_read(dev, 0x005A);
2713 backup[6] = b43_phy_read(dev, 0x0059);
2714 backup[7] = b43_phy_read(dev, 0x0058);
2715 backup[8] = b43_phy_read(dev, 0x000A);
2716 backup[9] = b43_phy_read(dev, 0x0003);
2717 backup[10] = b43_radio_read16(dev, 0x007A);
2718 backup[11] = b43_radio_read16(dev, 0x0043);
2720 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) & 0x7FFF);
2721 b43_phy_write(dev, 0x0001,
2722 (b43_phy_read(dev, 0x0001) & 0x3FFF) | 0x4000);
2723 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2724 b43_phy_write(dev, 0x0812,
2725 (b43_phy_read(dev, 0x0812) & 0xFFF3) | 0x0004);
2726 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & ~(0x1 | 0x2));
2727 if (phy->rev >= 6) {
2728 backup[12] = b43_phy_read(dev, 0x002E);
2729 backup[13] = b43_phy_read(dev, 0x002F);
2730 backup[14] = b43_phy_read(dev, 0x080F);
2731 backup[15] = b43_phy_read(dev, 0x0810);
2732 backup[16] = b43_phy_read(dev, 0x0801);
2733 backup[17] = b43_phy_read(dev, 0x0060);
2734 backup[18] = b43_phy_read(dev, 0x0014);
2735 backup[19] = b43_phy_read(dev, 0x0478);
2737 b43_phy_write(dev, 0x002E, 0);
2738 b43_phy_write(dev, 0x002F, 0);
2739 b43_phy_write(dev, 0x080F, 0);
2740 b43_phy_write(dev, 0x0810, 0);
2741 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478) | 0x0100);
2742 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801) | 0x0040);
2743 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) | 0x0040);
2744 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014) | 0x0200);
2746 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0070);
2747 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0080);
2750 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2754 for (i = 7; i >= 4; i--) {
2755 b43_radio_write16(dev, 0x007B, i);
2758 (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2761 if (v47F < 31 && saved == 0xFFFF)
2764 if (saved == 0xFFFF)
2767 b43_radio_write16(dev, 0x007A,
2768 b43_radio_read16(dev, 0x007A) & 0x007F);
2769 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2770 b43_phy_write(dev, 0x0814,
2771 b43_phy_read(dev, 0x0814) | 0x0001);
2772 b43_phy_write(dev, 0x0815,
2773 b43_phy_read(dev, 0x0815) & 0xFFFE);
2775 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2776 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x000C);
2777 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x0030);
2778 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x0030);
2779 b43_phy_write(dev, 0x005A, 0x0480);
2780 b43_phy_write(dev, 0x0059, 0x0810);
2781 b43_phy_write(dev, 0x0058, 0x000D);
2782 if (phy->rev == 0) {
2783 b43_phy_write(dev, 0x0003, 0x0122);
2785 b43_phy_write(dev, 0x000A, b43_phy_read(dev, 0x000A)
2788 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2789 b43_phy_write(dev, 0x0814,
2790 b43_phy_read(dev, 0x0814) | 0x0004);
2791 b43_phy_write(dev, 0x0815,
2792 b43_phy_read(dev, 0x0815) & 0xFFFB);
2794 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003) & 0xFF9F)
2796 b43_radio_write16(dev, 0x007A,
2797 b43_radio_read16(dev, 0x007A) | 0x000F);
2798 b43_set_all_gains(dev, 3, 0, 1);
2799 b43_radio_write16(dev, 0x0043, (b43_radio_read16(dev, 0x0043)
2800 & 0x00F0) | 0x000F);
2802 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2806 for (i = 0; i < 4; i++) {
2807 b43_radio_write16(dev, 0x007B, i);
2810 (s16) ((b43_phy_read(dev, 0x047F) >> 8) &
2814 if (v47F > -31 && saved == 0xFFFF)
2817 if (saved == 0xFFFF)
2822 b43_radio_write16(dev, 0x007B, saved);
2824 if (phy->rev >= 6) {
2825 b43_phy_write(dev, 0x002E, backup[12]);
2826 b43_phy_write(dev, 0x002F, backup[13]);
2827 b43_phy_write(dev, 0x080F, backup[14]);
2828 b43_phy_write(dev, 0x0810, backup[15]);
2830 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2831 b43_phy_write(dev, 0x0814, backup[3]);
2832 b43_phy_write(dev, 0x0815, backup[4]);
2834 b43_phy_write(dev, 0x005A, backup[5]);
2835 b43_phy_write(dev, 0x0059, backup[6]);
2836 b43_phy_write(dev, 0x0058, backup[7]);
2837 b43_phy_write(dev, 0x000A, backup[8]);
2838 b43_phy_write(dev, 0x0003, backup[9]);
2839 b43_radio_write16(dev, 0x0043, backup[11]);
2840 b43_radio_write16(dev, 0x007A, backup[10]);
2841 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x1 | 0x2);
2842 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) | 0x8000);
2843 b43_set_original_gains(dev);
2844 if (phy->rev >= 6) {
2845 b43_phy_write(dev, 0x0801, backup[16]);
2846 b43_phy_write(dev, 0x0060, backup[17]);
2847 b43_phy_write(dev, 0x0014, backup[18]);
2848 b43_phy_write(dev, 0x0478, backup[19]);
2850 b43_phy_write(dev, 0x0001, backup[0]);
2851 b43_phy_write(dev, 0x0812, backup[2]);
2852 b43_phy_write(dev, 0x0811, backup[1]);
2855 void b43_calc_nrssi_slope(struct b43_wldev *dev)
2857 struct b43_phy *phy = &dev->phy;
2858 u16 backup[18] = { 0 };
2862 switch (phy->type) {
2864 backup[0] = b43_radio_read16(dev, 0x007A);
2865 backup[1] = b43_radio_read16(dev, 0x0052);
2866 backup[2] = b43_radio_read16(dev, 0x0043);
2867 backup[3] = b43_phy_read(dev, 0x0030);
2868 backup[4] = b43_phy_read(dev, 0x0026);
2869 backup[5] = b43_phy_read(dev, 0x0015);
2870 backup[6] = b43_phy_read(dev, 0x002A);
2871 backup[7] = b43_phy_read(dev, 0x0020);
2872 backup[8] = b43_phy_read(dev, 0x005A);
2873 backup[9] = b43_phy_read(dev, 0x0059);
2874 backup[10] = b43_phy_read(dev, 0x0058);
2875 backup[11] = b43_read16(dev, 0x03E2);
2876 backup[12] = b43_read16(dev, 0x03E6);
2877 backup[13] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2879 tmp = b43_radio_read16(dev, 0x007A);
2880 tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
2881 b43_radio_write16(dev, 0x007A, tmp);
2882 b43_phy_write(dev, 0x0030, 0x00FF);
2883 b43_write16(dev, 0x03EC, 0x7F7F);
2884 b43_phy_write(dev, 0x0026, 0x0000);
2885 b43_phy_write(dev, 0x0015, b43_phy_read(dev, 0x0015) | 0x0020);
2886 b43_phy_write(dev, 0x002A, 0x08A3);
2887 b43_radio_write16(dev, 0x007A,
2888 b43_radio_read16(dev, 0x007A) | 0x0080);
2890 nrssi0 = (s16) b43_phy_read(dev, 0x0027);
2891 b43_radio_write16(dev, 0x007A,
2892 b43_radio_read16(dev, 0x007A) & 0x007F);
2893 if (phy->rev >= 2) {
2894 b43_write16(dev, 0x03E6, 0x0040);
2895 } else if (phy->rev == 0) {
2896 b43_write16(dev, 0x03E6, 0x0122);
2898 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2900 B43_MMIO_CHANNEL_EXT) & 0x2000);
2902 b43_phy_write(dev, 0x0020, 0x3F3F);
2903 b43_phy_write(dev, 0x0015, 0xF330);
2904 b43_radio_write16(dev, 0x005A, 0x0060);
2905 b43_radio_write16(dev, 0x0043,
2906 b43_radio_read16(dev, 0x0043) & 0x00F0);
2907 b43_phy_write(dev, 0x005A, 0x0480);
2908 b43_phy_write(dev, 0x0059, 0x0810);
2909 b43_phy_write(dev, 0x0058, 0x000D);
2912 nrssi1 = (s16) b43_phy_read(dev, 0x0027);
2913 b43_phy_write(dev, 0x0030, backup[3]);
2914 b43_radio_write16(dev, 0x007A, backup[0]);
2915 b43_write16(dev, 0x03E2, backup[11]);
2916 b43_phy_write(dev, 0x0026, backup[4]);
2917 b43_phy_write(dev, 0x0015, backup[5]);
2918 b43_phy_write(dev, 0x002A, backup[6]);
2919 b43_synth_pu_workaround(dev, phy->channel);
2921 b43_write16(dev, 0x03F4, backup[13]);
2923 b43_phy_write(dev, 0x0020, backup[7]);
2924 b43_phy_write(dev, 0x005A, backup[8]);
2925 b43_phy_write(dev, 0x0059, backup[9]);
2926 b43_phy_write(dev, 0x0058, backup[10]);
2927 b43_radio_write16(dev, 0x0052, backup[1]);
2928 b43_radio_write16(dev, 0x0043, backup[2]);
2930 if (nrssi0 == nrssi1)
2931 phy->nrssislope = 0x00010000;
2933 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2936 phy->nrssi[0] = nrssi0;
2937 phy->nrssi[1] = nrssi1;
2941 if (phy->radio_rev >= 9)
2943 if (phy->radio_rev == 8)
2944 b43_calc_nrssi_offset(dev);
2946 b43_phy_write(dev, B43_PHY_G_CRS,
2947 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2948 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2949 backup[7] = b43_read16(dev, 0x03E2);
2950 b43_write16(dev, 0x03E2, b43_read16(dev, 0x03E2) | 0x8000);
2951 backup[0] = b43_radio_read16(dev, 0x007A);
2952 backup[1] = b43_radio_read16(dev, 0x0052);
2953 backup[2] = b43_radio_read16(dev, 0x0043);
2954 backup[3] = b43_phy_read(dev, 0x0015);
2955 backup[4] = b43_phy_read(dev, 0x005A);
2956 backup[5] = b43_phy_read(dev, 0x0059);
2957 backup[6] = b43_phy_read(dev, 0x0058);
2958 backup[8] = b43_read16(dev, 0x03E6);
2959 backup[9] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2960 if (phy->rev >= 3) {
2961 backup[10] = b43_phy_read(dev, 0x002E);
2962 backup[11] = b43_phy_read(dev, 0x002F);
2963 backup[12] = b43_phy_read(dev, 0x080F);
2964 backup[13] = b43_phy_read(dev, B43_PHY_G_LO_CONTROL);
2965 backup[14] = b43_phy_read(dev, 0x0801);
2966 backup[15] = b43_phy_read(dev, 0x0060);
2967 backup[16] = b43_phy_read(dev, 0x0014);
2968 backup[17] = b43_phy_read(dev, 0x0478);
2969 b43_phy_write(dev, 0x002E, 0);
2970 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, 0);
2975 b43_phy_write(dev, 0x0478,
2976 b43_phy_read(dev, 0x0478)
2978 b43_phy_write(dev, 0x0801,
2979 b43_phy_read(dev, 0x0801)
2984 b43_phy_write(dev, 0x0801,
2985 b43_phy_read(dev, 0x0801)
2989 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060)
2991 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014)
2994 b43_radio_write16(dev, 0x007A,
2995 b43_radio_read16(dev, 0x007A) | 0x0070);
2996 b43_set_all_gains(dev, 0, 8, 0);
2997 b43_radio_write16(dev, 0x007A,
2998 b43_radio_read16(dev, 0x007A) & 0x00F7);
2999 if (phy->rev >= 2) {
3000 b43_phy_write(dev, 0x0811,
3001 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
3003 b43_phy_write(dev, 0x0812,
3004 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
3007 b43_radio_write16(dev, 0x007A,
3008 b43_radio_read16(dev, 0x007A) | 0x0080);
3011 nrssi0 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
3012 if (nrssi0 >= 0x0020)
3015 b43_radio_write16(dev, 0x007A,
3016 b43_radio_read16(dev, 0x007A) & 0x007F);
3017 if (phy->rev >= 2) {
3018 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003)
3019 & 0xFF9F) | 0x0040);
3022 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3023 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3025 b43_radio_write16(dev, 0x007A,
3026 b43_radio_read16(dev, 0x007A) | 0x000F);
3027 b43_phy_write(dev, 0x0015, 0xF330);
3028 if (phy->rev >= 2) {
3029 b43_phy_write(dev, 0x0812,
3030 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
3032 b43_phy_write(dev, 0x0811,
3033 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
3037 b43_set_all_gains(dev, 3, 0, 1);
3038 if (phy->radio_rev == 8) {
3039 b43_radio_write16(dev, 0x0043, 0x001F);
3041 tmp = b43_radio_read16(dev, 0x0052) & 0xFF0F;
3042 b43_radio_write16(dev, 0x0052, tmp | 0x0060);
3043 tmp = b43_radio_read16(dev, 0x0043) & 0xFFF0;
3044 b43_radio_write16(dev, 0x0043, tmp | 0x0009);
3046 b43_phy_write(dev, 0x005A, 0x0480);
3047 b43_phy_write(dev, 0x0059, 0x0810);
3048 b43_phy_write(dev, 0x0058, 0x000D);
3050 nrssi1 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
3051 if (nrssi1 >= 0x0020)
3053 if (nrssi0 == nrssi1)
3054 phy->nrssislope = 0x00010000;
3056 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
3058 phy->nrssi[0] = nrssi1;
3059 phy->nrssi[1] = nrssi0;
3061 if (phy->rev >= 3) {
3062 b43_phy_write(dev, 0x002E, backup[10]);
3063 b43_phy_write(dev, 0x002F, backup[11]);
3064 b43_phy_write(dev, 0x080F, backup[12]);
3065 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, backup[13]);
3067 if (phy->rev >= 2) {
3068 b43_phy_write(dev, 0x0812,
3069 b43_phy_read(dev, 0x0812) & 0xFFCF);
3070 b43_phy_write(dev, 0x0811,
3071 b43_phy_read(dev, 0x0811) & 0xFFCF);
3074 b43_radio_write16(dev, 0x007A, backup[0]);
3075 b43_radio_write16(dev, 0x0052, backup[1]);
3076 b43_radio_write16(dev, 0x0043, backup[2]);
3077 b43_write16(dev, 0x03E2, backup[7]);
3078 b43_write16(dev, 0x03E6, backup[8]);
3079 b43_write16(dev, B43_MMIO_CHANNEL_EXT, backup[9]);
3080 b43_phy_write(dev, 0x0015, backup[3]);
3081 b43_phy_write(dev, 0x005A, backup[4]);
3082 b43_phy_write(dev, 0x0059, backup[5]);
3083 b43_phy_write(dev, 0x0058, backup[6]);
3084 b43_synth_pu_workaround(dev, phy->channel);
3085 b43_phy_write(dev, 0x0802,
3086 b43_phy_read(dev, 0x0802) | (0x0001 | 0x0002));
3087 b43_set_original_gains(dev);
3088 b43_phy_write(dev, B43_PHY_G_CRS,
3089 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
3090 if (phy->rev >= 3) {
3091 b43_phy_write(dev, 0x0801, backup[14]);
3092 b43_phy_write(dev, 0x0060, backup[15]);
3093 b43_phy_write(dev, 0x0014, backup[16]);
3094 b43_phy_write(dev, 0x0478, backup[17]);
3096 b43_nrssi_mem_update(dev);
3097 b43_calc_nrssi_threshold(dev);
3104 void b43_calc_nrssi_threshold(struct b43_wldev *dev)
3106 struct b43_phy *phy = &dev->phy;
3112 switch (phy->type) {
3113 case B43_PHYTYPE_B:{
3114 if (phy->radio_ver != 0x2050)
3117 (dev->dev->bus->sprom.r1.
3118 boardflags_lo & B43_BFL_RSSI))
3121 if (phy->radio_rev >= 6) {
3123 (phy->nrssi[1] - phy->nrssi[0]) * 32;
3124 threshold += 20 * (phy->nrssi[0] + 1);
3127 threshold = phy->nrssi[1] - 5;
3129 threshold = limit_value(threshold, 0, 0x3E);
3130 b43_phy_read(dev, 0x0020); /* dummy read */
3131 b43_phy_write(dev, 0x0020,
3132 (((u16) threshold) << 8) | 0x001C);
3134 if (phy->radio_rev >= 6) {
3135 b43_phy_write(dev, 0x0087, 0x0E0D);
3136 b43_phy_write(dev, 0x0086, 0x0C0B);
3137 b43_phy_write(dev, 0x0085, 0x0A09);
3138 b43_phy_write(dev, 0x0084, 0x0808);
3139 b43_phy_write(dev, 0x0083, 0x0808);
3140 b43_phy_write(dev, 0x0082, 0x0604);
3141 b43_phy_write(dev, 0x0081, 0x0302);
3142 b43_phy_write(dev, 0x0080, 0x0100);
3148 !(dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI)) {
3149 tmp16 = b43_nrssi_hw_read(dev, 0x20);
3153 b43_phy_write(dev, 0x048A,
3154 (b43_phy_read(dev, 0x048A)
3155 & 0xF000) | 0x09EB);
3157 b43_phy_write(dev, 0x048A,
3158 (b43_phy_read(dev, 0x048A)
3159 & 0xF000) | 0x0AED);
3162 if (phy->interfmode == B43_INTERFMODE_NONWLAN) {
3165 } else if (!phy->aci_wlan_automatic && phy->aci_enable) {
3173 a = a * (phy->nrssi[1] - phy->nrssi[0]);
3174 a += (phy->nrssi[0] << 6);
3180 a = limit_value(a, -31, 31);
3182 b = b * (phy->nrssi[1] - phy->nrssi[0]);
3183 b += (phy->nrssi[0] << 6);
3189 b = limit_value(b, -31, 31);
3191 tmp_u16 = b43_phy_read(dev, 0x048A) & 0xF000;
3192 tmp_u16 |= ((u32) b & 0x0000003F);
3193 tmp_u16 |= (((u32) a & 0x0000003F) << 6);
3194 b43_phy_write(dev, 0x048A, tmp_u16);
3202 /* Stack implementation to save/restore values from the
3203 * interference mitigation code.
3204 * It is save to restore values in random order.
3206 static void _stack_save(u32 * _stackptr, size_t * stackidx,
3207 u8 id, u16 offset, u16 value)
3209 u32 *stackptr = &(_stackptr[*stackidx]);
3211 B43_WARN_ON(offset & 0xF000);
3212 B43_WARN_ON(id & 0xF0);
3214 *stackptr |= ((u32) id) << 12;
3215 *stackptr |= ((u32) value) << 16;
3217 B43_WARN_ON(*stackidx >= B43_INTERFSTACK_SIZE);
3220 static u16 _stack_restore(u32 * stackptr, u8 id, u16 offset)
3224 B43_WARN_ON(offset & 0xF000);
3225 B43_WARN_ON(id & 0xF0);
3226 for (i = 0; i < B43_INTERFSTACK_SIZE; i++, stackptr++) {
3227 if ((*stackptr & 0x00000FFF) != offset)
3229 if (((*stackptr & 0x0000F000) >> 12) != id)
3231 return ((*stackptr & 0xFFFF0000) >> 16);
3238 #define phy_stacksave(offset) \
3240 _stack_save(stack, &stackidx, 0x1, (offset), \
3241 b43_phy_read(dev, (offset))); \
3243 #define phy_stackrestore(offset) \
3245 b43_phy_write(dev, (offset), \
3246 _stack_restore(stack, 0x1, \
3249 #define radio_stacksave(offset) \
3251 _stack_save(stack, &stackidx, 0x2, (offset), \
3252 b43_radio_read16(dev, (offset))); \
3254 #define radio_stackrestore(offset) \
3256 b43_radio_write16(dev, (offset), \
3257 _stack_restore(stack, 0x2, \
3260 #define ofdmtab_stacksave(table, offset) \
3262 _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
3263 b43_ofdmtab_read16(dev, (table), (offset))); \
3265 #define ofdmtab_stackrestore(table, offset) \
3267 b43_ofdmtab_write16(dev, (table), (offset), \
3268 _stack_restore(stack, 0x3, \
3269 (offset)|(table))); \
3273 b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
3275 struct b43_phy *phy = &dev->phy;
3277 size_t stackidx = 0;
3278 u32 *stack = phy->interfstack;
3281 case B43_INTERFMODE_NONWLAN:
3282 if (phy->rev != 1) {
3283 b43_phy_write(dev, 0x042B,
3284 b43_phy_read(dev, 0x042B) | 0x0800);
3285 b43_phy_write(dev, B43_PHY_G_CRS,
3287 B43_PHY_G_CRS) & ~0x4000);
3290 radio_stacksave(0x0078);
3291 tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
3292 flipped = flip_4bit(tmp);
3293 if (flipped < 10 && flipped >= 8)
3295 else if (flipped >= 10)
3297 flipped = flip_4bit(flipped);
3298 flipped = (flipped << 1) | 0x0020;
3299 b43_radio_write16(dev, 0x0078, flipped);
3301 b43_calc_nrssi_threshold(dev);
3303 phy_stacksave(0x0406);
3304 b43_phy_write(dev, 0x0406, 0x7E28);
3306 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x0800);
3307 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3309 B43_PHY_RADIO_BITFIELD) | 0x1000);
3311 phy_stacksave(0x04A0);
3312 b43_phy_write(dev, 0x04A0,
3313 (b43_phy_read(dev, 0x04A0) & 0xC0C0) | 0x0008);
3314 phy_stacksave(0x04A1);
3315 b43_phy_write(dev, 0x04A1,
3316 (b43_phy_read(dev, 0x04A1) & 0xC0C0) | 0x0605);
3317 phy_stacksave(0x04A2);
3318 b43_phy_write(dev, 0x04A2,
3319 (b43_phy_read(dev, 0x04A2) & 0xC0C0) | 0x0204);
3320 phy_stacksave(0x04A8);
3321 b43_phy_write(dev, 0x04A8,
3322 (b43_phy_read(dev, 0x04A8) & 0xC0C0) | 0x0803);
3323 phy_stacksave(0x04AB);
3324 b43_phy_write(dev, 0x04AB,
3325 (b43_phy_read(dev, 0x04AB) & 0xC0C0) | 0x0605);
3327 phy_stacksave(0x04A7);
3328 b43_phy_write(dev, 0x04A7, 0x0002);
3329 phy_stacksave(0x04A3);
3330 b43_phy_write(dev, 0x04A3, 0x287A);
3331 phy_stacksave(0x04A9);
3332 b43_phy_write(dev, 0x04A9, 0x2027);
3333 phy_stacksave(0x0493);
3334 b43_phy_write(dev, 0x0493, 0x32F5);
3335 phy_stacksave(0x04AA);
3336 b43_phy_write(dev, 0x04AA, 0x2027);
3337 phy_stacksave(0x04AC);
3338 b43_phy_write(dev, 0x04AC, 0x32F5);
3340 case B43_INTERFMODE_MANUALWLAN:
3341 if (b43_phy_read(dev, 0x0033) & 0x0800)
3344 phy->aci_enable = 1;
3346 phy_stacksave(B43_PHY_RADIO_BITFIELD);
3347 phy_stacksave(B43_PHY_G_CRS);
3349 phy_stacksave(0x0406);
3351 phy_stacksave(0x04C0);
3352 phy_stacksave(0x04C1);
3354 phy_stacksave(0x0033);
3355 phy_stacksave(0x04A7);
3356 phy_stacksave(0x04A3);
3357 phy_stacksave(0x04A9);
3358 phy_stacksave(0x04AA);
3359 phy_stacksave(0x04AC);
3360 phy_stacksave(0x0493);
3361 phy_stacksave(0x04A1);
3362 phy_stacksave(0x04A0);
3363 phy_stacksave(0x04A2);
3364 phy_stacksave(0x048A);
3365 phy_stacksave(0x04A8);
3366 phy_stacksave(0x04AB);
3367 if (phy->rev == 2) {
3368 phy_stacksave(0x04AD);
3369 phy_stacksave(0x04AE);
3370 } else if (phy->rev >= 3) {
3371 phy_stacksave(0x04AD);
3372 phy_stacksave(0x0415);
3373 phy_stacksave(0x0416);
3374 phy_stacksave(0x0417);
3375 ofdmtab_stacksave(0x1A00, 0x2);
3376 ofdmtab_stacksave(0x1A00, 0x3);
3378 phy_stacksave(0x042B);
3379 phy_stacksave(0x048C);
3381 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3382 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3384 b43_phy_write(dev, B43_PHY_G_CRS,
3385 (b43_phy_read(dev, B43_PHY_G_CRS)
3386 & 0xFFFC) | 0x0002);
3388 b43_phy_write(dev, 0x0033, 0x0800);
3389 b43_phy_write(dev, 0x04A3, 0x2027);
3390 b43_phy_write(dev, 0x04A9, 0x1CA8);
3391 b43_phy_write(dev, 0x0493, 0x287A);
3392 b43_phy_write(dev, 0x04AA, 0x1CA8);
3393 b43_phy_write(dev, 0x04AC, 0x287A);
3395 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3396 & 0xFFC0) | 0x001A);
3397 b43_phy_write(dev, 0x04A7, 0x000D);
3400 b43_phy_write(dev, 0x0406, 0xFF0D);
3401 } else if (phy->rev == 2) {
3402 b43_phy_write(dev, 0x04C0, 0xFFFF);
3403 b43_phy_write(dev, 0x04C1, 0x00A9);
3405 b43_phy_write(dev, 0x04C0, 0x00C1);
3406 b43_phy_write(dev, 0x04C1, 0x0059);
3409 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3410 & 0xC0FF) | 0x1800);
3411 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3412 & 0xFFC0) | 0x0015);
3413 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3414 & 0xCFFF) | 0x1000);
3415 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3416 & 0xF0FF) | 0x0A00);
3417 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3418 & 0xCFFF) | 0x1000);
3419 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3420 & 0xF0FF) | 0x0800);
3421 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3422 & 0xFFCF) | 0x0010);
3423 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3424 & 0xFFF0) | 0x0005);
3425 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3426 & 0xFFCF) | 0x0010);
3427 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3428 & 0xFFF0) | 0x0006);
3429 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3430 & 0xF0FF) | 0x0800);
3431 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3432 & 0xF0FF) | 0x0500);
3433 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3434 & 0xFFF0) | 0x000B);
3436 if (phy->rev >= 3) {
3437 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3439 b43_phy_write(dev, 0x0415, (b43_phy_read(dev, 0x0415)
3440 & 0x8000) | 0x36D8);
3441 b43_phy_write(dev, 0x0416, (b43_phy_read(dev, 0x0416)
3442 & 0x8000) | 0x36D8);
3443 b43_phy_write(dev, 0x0417, (b43_phy_read(dev, 0x0417)
3444 & 0xFE00) | 0x016D);
3446 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3448 b43_phy_write(dev, 0x048A, (b43_phy_read(dev, 0x048A)
3449 & 0x9FFF) | 0x2000);
3450 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ACIW);
3452 if (phy->rev >= 2) {
3453 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B)
3456 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
3457 & 0xF0FF) | 0x0200);
3458 if (phy->rev == 2) {
3459 b43_phy_write(dev, 0x04AE, (b43_phy_read(dev, 0x04AE)
3460 & 0xFF00) | 0x007F);
3461 b43_phy_write(dev, 0x04AD, (b43_phy_read(dev, 0x04AD)
3462 & 0x00FF) | 0x1300);
3463 } else if (phy->rev >= 6) {
3464 b43_ofdmtab_write16(dev, 0x1A00, 0x3, 0x007F);
3465 b43_ofdmtab_write16(dev, 0x1A00, 0x2, 0x007F);
3466 b43_phy_write(dev, 0x04AD, b43_phy_read(dev, 0x04AD)
3469 b43_calc_nrssi_slope(dev);
3477 b43_radio_interference_mitigation_disable(struct b43_wldev *dev, int mode)
3479 struct b43_phy *phy = &dev->phy;
3480 u32 *stack = phy->interfstack;
3483 case B43_INTERFMODE_NONWLAN:
3484 if (phy->rev != 1) {
3485 b43_phy_write(dev, 0x042B,
3486 b43_phy_read(dev, 0x042B) & ~0x0800);
3487 b43_phy_write(dev, B43_PHY_G_CRS,
3489 B43_PHY_G_CRS) | 0x4000);
3492 radio_stackrestore(0x0078);
3493 b43_calc_nrssi_threshold(dev);
3494 phy_stackrestore(0x0406);
3495 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) & ~0x0800);
3496 if (!dev->bad_frames_preempt) {
3497 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3498 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3501 b43_phy_write(dev, B43_PHY_G_CRS,
3502 b43_phy_read(dev, B43_PHY_G_CRS) | 0x4000);
3503 phy_stackrestore(0x04A0);
3504 phy_stackrestore(0x04A1);
3505 phy_stackrestore(0x04A2);
3506 phy_stackrestore(0x04A8);
3507 phy_stackrestore(0x04AB);
3508 phy_stackrestore(0x04A7);
3509 phy_stackrestore(0x04A3);
3510 phy_stackrestore(0x04A9);
3511 phy_stackrestore(0x0493);
3512 phy_stackrestore(0x04AA);
3513 phy_stackrestore(0x04AC);
3515 case B43_INTERFMODE_MANUALWLAN:
3516 if (!(b43_phy_read(dev, 0x0033) & 0x0800))
3519 phy->aci_enable = 0;
3521 phy_stackrestore(B43_PHY_RADIO_BITFIELD);
3522 phy_stackrestore(B43_PHY_G_CRS);
3523 phy_stackrestore(0x0033);
3524 phy_stackrestore(0x04A3);
3525 phy_stackrestore(0x04A9);
3526 phy_stackrestore(0x0493);
3527 phy_stackrestore(0x04AA);
3528 phy_stackrestore(0x04AC);
3529 phy_stackrestore(0x04A0);
3530 phy_stackrestore(0x04A7);
3531 if (phy->rev >= 2) {
3532 phy_stackrestore(0x04C0);
3533 phy_stackrestore(0x04C1);
3535 phy_stackrestore(0x0406);
3536 phy_stackrestore(0x04A1);
3537 phy_stackrestore(0x04AB);
3538 phy_stackrestore(0x04A8);
3539 if (phy->rev == 2) {
3540 phy_stackrestore(0x04AD);
3541 phy_stackrestore(0x04AE);
3542 } else if (phy->rev >= 3) {
3543 phy_stackrestore(0x04AD);
3544 phy_stackrestore(0x0415);
3545 phy_stackrestore(0x0416);
3546 phy_stackrestore(0x0417);
3547 ofdmtab_stackrestore(0x1A00, 0x2);
3548 ofdmtab_stackrestore(0x1A00, 0x3);
3550 phy_stackrestore(0x04A2);
3551 phy_stackrestore(0x048A);
3552 phy_stackrestore(0x042B);
3553 phy_stackrestore(0x048C);
3554 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ACIW);
3555 b43_calc_nrssi_slope(dev);
3562 #undef phy_stacksave
3563 #undef phy_stackrestore
3564 #undef radio_stacksave
3565 #undef radio_stackrestore
3566 #undef ofdmtab_stacksave
3567 #undef ofdmtab_stackrestore
3569 int b43_radio_set_interference_mitigation(struct b43_wldev *dev, int mode)
3571 struct b43_phy *phy = &dev->phy;
3574 if ((phy->type != B43_PHYTYPE_G) || (phy->rev == 0) || (!phy->gmode))
3577 phy->aci_wlan_automatic = 0;
3579 case B43_INTERFMODE_AUTOWLAN:
3580 phy->aci_wlan_automatic = 1;
3581 if (phy->aci_enable)
3582 mode = B43_INTERFMODE_MANUALWLAN;
3584 mode = B43_INTERFMODE_NONE;
3586 case B43_INTERFMODE_NONE:
3587 case B43_INTERFMODE_NONWLAN:
3588 case B43_INTERFMODE_MANUALWLAN:
3594 currentmode = phy->interfmode;
3595 if (currentmode == mode)
3597 if (currentmode != B43_INTERFMODE_NONE)
3598 b43_radio_interference_mitigation_disable(dev, currentmode);
3600 if (mode == B43_INTERFMODE_NONE) {
3601 phy->aci_enable = 0;
3602 phy->aci_hw_rssi = 0;
3604 b43_radio_interference_mitigation_enable(dev, mode);
3605 phy->interfmode = mode;
3610 static u16 b43_radio_core_calibration_value(struct b43_wldev *dev)
3612 u16 reg, index, ret;
3614 static const u8 rcc_table[] = {
3615 0x02, 0x03, 0x01, 0x0F,
3616 0x06, 0x07, 0x05, 0x0F,
3617 0x0A, 0x0B, 0x09, 0x0F,
3618 0x0E, 0x0F, 0x0D, 0x0F,
3621 reg = b43_radio_read16(dev, 0x60);
3622 index = (reg & 0x001E) >> 1;
3623 ret = rcc_table[index] << 1;
3624 ret |= (reg & 0x0001);
3630 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
3631 static u16 radio2050_rfover_val(struct b43_wldev *dev,
3632 u16 phy_register, unsigned int lpd)
3634 struct b43_phy *phy = &dev->phy;
3635 struct ssb_sprom *sprom = &(dev->dev->bus->sprom);
3640 if (has_loopback_gain(phy)) {
3641 int max_lb_gain = phy->max_lb_gain;
3645 if (phy->radio_rev == 8)
3646 max_lb_gain += 0x3E;
3648 max_lb_gain += 0x26;
3649 if (max_lb_gain >= 0x46) {
3651 max_lb_gain -= 0x46;
3652 } else if (max_lb_gain >= 0x3A) {
3654 max_lb_gain -= 0x3A;
3655 } else if (max_lb_gain >= 0x2E) {
3657 max_lb_gain -= 0x2E;
3660 max_lb_gain -= 0x10;
3663 for (i = 0; i < 16; i++) {
3664 max_lb_gain -= (i * 6);
3665 if (max_lb_gain < 6)
3669 if ((phy->rev < 7) ||
3670 !(sprom->r1.boardflags_lo & B43_BFL_EXTLNA)) {
3671 if (phy_register == B43_PHY_RFOVER) {
3673 } else if (phy_register == B43_PHY_RFOVERVAL) {
3680 return (0x0092 | extlna);
3682 return (0x0093 | extlna);
3688 if (phy_register == B43_PHY_RFOVER) {
3690 } else if (phy_register == B43_PHY_RFOVERVAL) {
3698 return (0x8092 | extlna);
3700 return (0x2092 | extlna);
3702 return (0x2093 | extlna);
3709 if ((phy->rev < 7) ||
3710 !(sprom->r1.boardflags_lo & B43_BFL_EXTLNA)) {
3711 if (phy_register == B43_PHY_RFOVER) {
3713 } else if (phy_register == B43_PHY_RFOVERVAL) {
3728 if (phy_register == B43_PHY_RFOVER) {
3730 } else if (phy_register == B43_PHY_RFOVERVAL) {
3749 struct init2050_saved_values {
3750 /* Core registers */
3754 /* Radio registers */
3767 u16 phy_analogoverval;
3775 u16 b43_radio_init2050(struct b43_wldev *dev)
3777 struct b43_phy *phy = &dev->phy;
3778 struct init2050_saved_values sav;
3783 u32 tmp1 = 0, tmp2 = 0;
3785 memset(&sav, 0, sizeof(sav)); /* get rid of "may be used uninitialized..." */
3787 sav.radio_43 = b43_radio_read16(dev, 0x43);
3788 sav.radio_51 = b43_radio_read16(dev, 0x51);
3789 sav.radio_52 = b43_radio_read16(dev, 0x52);
3790 sav.phy_pgactl = b43_phy_read(dev, B43_PHY_PGACTL);
3791 sav.phy_base_5A = b43_phy_read(dev, B43_PHY_BASE(0x5A));
3792 sav.phy_base_59 = b43_phy_read(dev, B43_PHY_BASE(0x59));
3793 sav.phy_base_58 = b43_phy_read(dev, B43_PHY_BASE(0x58));
3795 if (phy->type == B43_PHYTYPE_B) {
3796 sav.phy_base_30 = b43_phy_read(dev, B43_PHY_BASE(0x30));
3797 sav.reg_3EC = b43_read16(dev, 0x3EC);
3799 b43_phy_write(dev, B43_PHY_BASE(0x30), 0xFF);
3800 b43_write16(dev, 0x3EC, 0x3F3F);
3801 } else if (phy->gmode || phy->rev >= 2) {
3802 sav.phy_rfover = b43_phy_read(dev, B43_PHY_RFOVER);
3803 sav.phy_rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
3804 sav.phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
3805 sav.phy_analogoverval =
3806 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
3807 sav.phy_crs0 = b43_phy_read(dev, B43_PHY_CRS0);
3808 sav.phy_classctl = b43_phy_read(dev, B43_PHY_CLASSCTL);
3810 b43_phy_write(dev, B43_PHY_ANALOGOVER,
3811 b43_phy_read(dev, B43_PHY_ANALOGOVER)
3813 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3814 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL)
3816 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
3818 b43_phy_write(dev, B43_PHY_CLASSCTL,
3819 b43_phy_read(dev, B43_PHY_CLASSCTL)
3821 if (has_loopback_gain(phy)) {
3822 sav.phy_lo_mask = b43_phy_read(dev, B43_PHY_LO_MASK);
3823 sav.phy_lo_ctl = b43_phy_read(dev, B43_PHY_LO_CTL);
3826 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
3828 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
3829 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
3832 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3833 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3835 b43_phy_write(dev, B43_PHY_RFOVER,
3836 radio2050_rfover_val(dev, B43_PHY_RFOVER, 0));
3838 b43_write16(dev, 0x3E2, b43_read16(dev, 0x3E2) | 0x8000);
3840 sav.phy_syncctl = b43_phy_read(dev, B43_PHY_SYNCCTL);
3841 b43_phy_write(dev, B43_PHY_SYNCCTL, b43_phy_read(dev, B43_PHY_SYNCCTL)
3843 sav.reg_3E6 = b43_read16(dev, 0x3E6);
3844 sav.reg_3F4 = b43_read16(dev, 0x3F4);
3846 if (phy->analog == 0) {
3847 b43_write16(dev, 0x03E6, 0x0122);
3849 if (phy->analog >= 2) {
3850 b43_phy_write(dev, B43_PHY_BASE(0x03),
3851 (b43_phy_read(dev, B43_PHY_BASE(0x03))
3854 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3855 (b43_read16(dev, B43_MMIO_CHANNEL_EXT) | 0x2000));
3858 rcc = b43_radio_core_calibration_value(dev);
3860 if (phy->type == B43_PHYTYPE_B)
3861 b43_radio_write16(dev, 0x78, 0x26);
3862 if (phy->gmode || phy->rev >= 2) {
3863 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3864 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3867 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFAF);
3868 b43_phy_write(dev, B43_PHY_BASE(0x2B), 0x1403);
3869 if (phy->gmode || phy->rev >= 2) {
3870 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3871 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3874 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFA0);
3875 b43_radio_write16(dev, 0x51, b43_radio_read16(dev, 0x51)
3877 if (phy->radio_rev == 8) {
3878 b43_radio_write16(dev, 0x43, 0x1F);
3880 b43_radio_write16(dev, 0x52, 0);
3881 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
3882 & 0xFFF0) | 0x0009);
3884 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3886 for (i = 0; i < 16; i++) {
3887 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0480);
3888 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3889 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3890 if (phy->gmode || phy->rev >= 2) {
3891 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3892 radio2050_rfover_val(dev,
3896 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3898 if (phy->gmode || phy->rev >= 2) {
3899 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3900 radio2050_rfover_val(dev,
3904 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3906 if (phy->gmode || phy->rev >= 2) {
3907 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3908 radio2050_rfover_val(dev,
3912 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3914 tmp1 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3915 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3916 if (phy->gmode || phy->rev >= 2) {
3917 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3918 radio2050_rfover_val(dev,
3922 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3926 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3930 for (i = 0; i < 16; i++) {
3931 radio78 = ((flip_4bit(i) << 1) | 0x20);
3932 b43_radio_write16(dev, 0x78, radio78);
3934 for (j = 0; j < 16; j++) {
3935 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0D80);
3936 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3937 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3938 if (phy->gmode || phy->rev >= 2) {
3939 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3940 radio2050_rfover_val(dev,
3945 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3947 if (phy->gmode || phy->rev >= 2) {
3948 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3949 radio2050_rfover_val(dev,
3954 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3956 if (phy->gmode || phy->rev >= 2) {
3957 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3958 radio2050_rfover_val(dev,
3963 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3965 tmp2 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3966 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3967 if (phy->gmode || phy->rev >= 2) {
3968 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3969 radio2050_rfover_val(dev,
3974 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3982 /* Restore the registers */
3983 b43_phy_write(dev, B43_PHY_PGACTL, sav.phy_pgactl);
3984 b43_radio_write16(dev, 0x51, sav.radio_51);
3985 b43_radio_write16(dev, 0x52, sav.radio_52);
3986 b43_radio_write16(dev, 0x43, sav.radio_43);
3987 b43_phy_write(dev, B43_PHY_BASE(0x5A), sav.phy_base_5A);
3988 b43_phy_write(dev, B43_PHY_BASE(0x59), sav.phy_base_59);
3989 b43_phy_write(dev, B43_PHY_BASE(0x58), sav.phy_base_58);
3990 b43_write16(dev, 0x3E6, sav.reg_3E6);
3991 if (phy->analog != 0)
3992 b43_write16(dev, 0x3F4, sav.reg_3F4);
3993 b43_phy_write(dev, B43_PHY_SYNCCTL, sav.phy_syncctl);
3994 b43_synth_pu_workaround(dev, phy->channel);
3995 if (phy->type == B43_PHYTYPE_B) {
3996 b43_phy_write(dev, B43_PHY_BASE(0x30), sav.phy_base_30);
3997 b43_write16(dev, 0x3EC, sav.reg_3EC);
3998 } else if (phy->gmode) {
3999 b43_write16(dev, B43_MMIO_PHY_RADIO,
4000 b43_read16(dev, B43_MMIO_PHY_RADIO)
4002 b43_phy_write(dev, B43_PHY_RFOVER, sav.phy_rfover);
4003 b43_phy_write(dev, B43_PHY_RFOVERVAL, sav.phy_rfoverval);
4004 b43_phy_write(dev, B43_PHY_ANALOGOVER, sav.phy_analogover);
4005 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
4006 sav.phy_analogoverval);
4007 b43_phy_write(dev, B43_PHY_CRS0, sav.phy_crs0);
4008 b43_phy_write(dev, B43_PHY_CLASSCTL, sav.phy_classctl);
4009 if (has_loopback_gain(phy)) {
4010 b43_phy_write(dev, B43_PHY_LO_MASK, sav.phy_lo_mask);
4011 b43_phy_write(dev, B43_PHY_LO_CTL, sav.phy_lo_ctl);
4022 void b43_radio_init2060(struct b43_wldev *dev)
4026 b43_radio_write16(dev, 0x0004, 0x00C0);
4027 b43_radio_write16(dev, 0x0005, 0x0008);
4028 b43_radio_write16(dev, 0x0009, 0x0040);
4029 b43_radio_write16(dev, 0x0005, 0x00AA);
4030 b43_radio_write16(dev, 0x0032, 0x008F);
4031 b43_radio_write16(dev, 0x0006, 0x008F);
4032 b43_radio_write16(dev, 0x0034, 0x008F);
4033 b43_radio_write16(dev, 0x002C, 0x0007);
4034 b43_radio_write16(dev, 0x0082, 0x0080);
4035 b43_radio_write16(dev, 0x0080, 0x0000);
4036 b43_radio_write16(dev, 0x003F, 0x00DA);
4037 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
4038 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0010);
4039 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
4040 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
4041 msleep(1); /* delay 400usec */
4043 b43_radio_write16(dev, 0x0081,
4044 (b43_radio_read16(dev, 0x0081) & ~0x0020) | 0x0010);
4045 msleep(1); /* delay 400usec */
4047 b43_radio_write16(dev, 0x0005,
4048 (b43_radio_read16(dev, 0x0005) & ~0x0008) | 0x0008);
4049 b43_radio_write16(dev, 0x0085, b43_radio_read16(dev, 0x0085) & ~0x0010);
4050 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
4051 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0040);
4052 b43_radio_write16(dev, 0x0081,
4053 (b43_radio_read16(dev, 0x0081) & ~0x0040) | 0x0040);
4054 b43_radio_write16(dev, 0x0005,
4055 (b43_radio_read16(dev, 0x0081) & ~0x0008) | 0x0008);
4056 b43_phy_write(dev, 0x0063, 0xDDC6);
4057 b43_phy_write(dev, 0x0069, 0x07BE);
4058 b43_phy_write(dev, 0x006A, 0x0000);
4060 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_A, 0);
4066 static inline u16 freq_r3A_value(u16 frequency)
4070 if (frequency < 5091)
4072 else if (frequency < 5321)
4074 else if (frequency < 5806)
4082 void b43_radio_set_tx_iq(struct b43_wldev *dev)
4084 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
4085 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
4086 u16 tmp = b43_radio_read16(dev, 0x001E);
4089 for (i = 0; i < 5; i++) {
4090 for (j = 0; j < 5; j++) {
4091 if (tmp == (data_high[i] << 4 | data_low[j])) {
4092 b43_phy_write(dev, 0x0069,
4093 (i - j) << 8 | 0x00C0);
4100 int b43_radio_selectchannel(struct b43_wldev *dev,
4101 u8 channel, int synthetic_pu_workaround)
4103 struct b43_phy *phy = &dev->phy;
4108 if (channel == 0xFF) {
4109 switch (phy->type) {
4111 channel = B43_DEFAULT_CHANNEL_A;
4115 channel = B43_DEFAULT_CHANNEL_BG;
4122 /* First we set the channel radio code to prevent the
4123 * firmware from sending ghost packets.
4125 channelcookie = channel;
4126 if (phy->type == B43_PHYTYPE_A)
4127 channelcookie |= 0x100;
4128 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
4130 if (phy->type == B43_PHYTYPE_A) {
4133 freq = channel2freq_a(channel);
4135 r8 = b43_radio_read16(dev, 0x0008);
4136 b43_write16(dev, 0x03F0, freq);
4137 b43_radio_write16(dev, 0x0008, r8);
4139 //TODO: write max channel TX power? to Radio 0x2D
4140 tmp = b43_radio_read16(dev, 0x002E);
4142 //TODO: OR tmp with the Power out estimation for this channel?
4143 b43_radio_write16(dev, 0x002E, tmp);
4145 if (freq >= 4920 && freq <= 5500) {
4147 * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
4148 * = (freq * 0.025862069
4150 r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
4152 b43_radio_write16(dev, 0x0007, (r8 << 4) | r8);
4153 b43_radio_write16(dev, 0x0020, (r8 << 4) | r8);
4154 b43_radio_write16(dev, 0x0021, (r8 << 4) | r8);
4155 b43_radio_write16(dev, 0x0022, (b43_radio_read16(dev, 0x0022)
4156 & 0x000F) | (r8 << 4));
4157 b43_radio_write16(dev, 0x002A, (r8 << 4));
4158 b43_radio_write16(dev, 0x002B, (r8 << 4));
4159 b43_radio_write16(dev, 0x0008, (b43_radio_read16(dev, 0x0008)
4160 & 0x00F0) | (r8 << 4));
4161 b43_radio_write16(dev, 0x0029, (b43_radio_read16(dev, 0x0029)
4162 & 0xFF0F) | 0x00B0);
4163 b43_radio_write16(dev, 0x0035, 0x00AA);
4164 b43_radio_write16(dev, 0x0036, 0x0085);
4165 b43_radio_write16(dev, 0x003A, (b43_radio_read16(dev, 0x003A)
4167 freq_r3A_value(freq));
4168 b43_radio_write16(dev, 0x003D,
4169 b43_radio_read16(dev, 0x003D) & 0x00FF);
4170 b43_radio_write16(dev, 0x0081, (b43_radio_read16(dev, 0x0081)
4171 & 0xFF7F) | 0x0080);
4172 b43_radio_write16(dev, 0x0035,
4173 b43_radio_read16(dev, 0x0035) & 0xFFEF);
4174 b43_radio_write16(dev, 0x0035, (b43_radio_read16(dev, 0x0035)
4175 & 0xFFEF) | 0x0010);
4176 b43_radio_set_tx_iq(dev);
4177 //TODO: TSSI2dbm workaround
4178 b43_phy_xmitpower(dev); //FIXME correct?
4180 if ((channel < 1) || (channel > 14))
4183 if (synthetic_pu_workaround)
4184 b43_synth_pu_workaround(dev, channel);
4186 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
4188 if (channel == 14) {
4189 if (dev->dev->bus->sprom.r1.country_code ==
4190 SSB_SPROM1CCODE_JAPAN)
4192 b43_hf_read(dev) & ~B43_HF_ACPR);
4195 b43_hf_read(dev) | B43_HF_ACPR);
4196 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
4197 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
4200 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
4201 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
4206 phy->channel = channel;
4207 /* Wait for the radio to tune to the channel and stabilize. */
4213 /* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
4214 static u16 b43_get_txgain_base_band(u16 txpower)
4218 B43_WARN_ON(txpower > 63);
4222 else if (txpower >= 49)
4224 else if (txpower >= 44)
4232 /* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
4233 static u16 b43_get_txgain_freq_power_amp(u16 txpower)
4237 B43_WARN_ON(txpower > 63);
4241 else if (txpower >= 25)
4243 else if (txpower >= 20)
4245 else if (txpower >= 12)
4253 /* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
4254 static u16 b43_get_txgain_dac(u16 txpower)
4258 B43_WARN_ON(txpower > 63);
4262 else if (txpower >= 49)
4264 else if (txpower >= 44)
4266 else if (txpower >= 32)
4268 else if (txpower >= 25)
4270 else if (txpower >= 20)
4272 else if (txpower >= 12)
4280 static void b43_radio_set_txpower_a(struct b43_wldev *dev, u16 txpower)
4282 struct b43_phy *phy = &dev->phy;
4283 u16 pamp, base, dac, t;
4285 txpower = limit_value(txpower, 0, 63);
4287 pamp = b43_get_txgain_freq_power_amp(txpower);
4290 b43_phy_write(dev, 0x0019, pamp);
4292 base = b43_get_txgain_base_band(txpower);
4294 b43_phy_write(dev, 0x0017, base | 0x0020);
4296 t = b43_ofdmtab_read16(dev, 0x3000, 1);
4299 dac = b43_get_txgain_dac(txpower);
4303 b43_ofdmtab_write16(dev, 0x3000, 1, dac);
4305 phy->txpwr_offset = txpower;
4307 //TODO: FuncPlaceholder (Adjust BB loft cancel)
4310 void b43_radio_turn_on(struct b43_wldev *dev)
4312 struct b43_phy *phy = &dev->phy;
4321 switch (phy->type) {
4323 b43_radio_write16(dev, 0x0004, 0x00C0);
4324 b43_radio_write16(dev, 0x0005, 0x0008);
4325 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) & 0xFFF7);
4326 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) & 0xFFF7);
4327 b43_radio_init2060(dev);
4331 b43_phy_write(dev, 0x0015, 0x8000);
4332 b43_phy_write(dev, 0x0015, 0xCC00);
4333 b43_phy_write(dev, 0x0015, (phy->gmode ? 0x00C0 : 0x0000));
4334 if (phy->radio_off_context.valid) {
4335 /* Restore the RFover values. */
4336 b43_phy_write(dev, B43_PHY_RFOVER,
4337 phy->radio_off_context.rfover);
4338 b43_phy_write(dev, B43_PHY_RFOVERVAL,
4339 phy->radio_off_context.rfoverval);
4340 phy->radio_off_context.valid = 0;
4342 channel = phy->channel;
4343 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_BG, 1);
4344 err |= b43_radio_selectchannel(dev, channel, 0);
4353 void b43_radio_turn_off(struct b43_wldev *dev, bool force)
4355 struct b43_phy *phy = &dev->phy;
4357 if (!phy->radio_on && !force)
4360 if (phy->type == B43_PHYTYPE_A) {
4361 b43_radio_write16(dev, 0x0004, 0x00FF);
4362 b43_radio_write16(dev, 0x0005, 0x00FB);
4363 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) | 0x0008);
4364 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) | 0x0008);
4366 if (phy->type == B43_PHYTYPE_G && dev->dev->id.revision >= 5) {
4367 u16 rfover, rfoverval;
4369 rfover = b43_phy_read(dev, B43_PHY_RFOVER);
4370 rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
4372 phy->radio_off_context.rfover = rfover;
4373 phy->radio_off_context.rfoverval = rfoverval;
4374 phy->radio_off_context.valid = 1;
4376 b43_phy_write(dev, B43_PHY_RFOVER, rfover | 0x008C);
4377 b43_phy_write(dev, B43_PHY_RFOVERVAL, rfoverval & 0xFF73);
4379 b43_phy_write(dev, 0x0015, 0xAA00);