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>
29 #include <linux/types.h>
37 static const s8 b43_tssi2dbm_b_table[] = {
38 0x4D, 0x4C, 0x4B, 0x4A,
39 0x4A, 0x49, 0x48, 0x47,
40 0x47, 0x46, 0x45, 0x45,
41 0x44, 0x43, 0x42, 0x42,
42 0x41, 0x40, 0x3F, 0x3E,
43 0x3D, 0x3C, 0x3B, 0x3A,
44 0x39, 0x38, 0x37, 0x36,
45 0x35, 0x34, 0x32, 0x31,
46 0x30, 0x2F, 0x2D, 0x2C,
47 0x2B, 0x29, 0x28, 0x26,
48 0x25, 0x23, 0x21, 0x1F,
49 0x1D, 0x1A, 0x17, 0x14,
50 0x10, 0x0C, 0x06, 0x00,
56 static const s8 b43_tssi2dbm_g_table[] = {
75 const u8 b43_radio_channel_codes_bg[] = {
82 static void b43_phy_initg(struct b43_wldev *dev);
84 /* Reverse the bits of a 4bit value.
85 * Example: 1101 is flipped 1011
87 static u16 flip_4bit(u16 value)
91 B43_WARN_ON(value & ~0x000F);
93 flipped |= (value & 0x0001) << 3;
94 flipped |= (value & 0x0002) << 1;
95 flipped |= (value & 0x0004) >> 1;
96 flipped |= (value & 0x0008) >> 3;
101 static void generate_rfatt_list(struct b43_wldev *dev,
102 struct b43_rfatt_list *list)
104 struct b43_phy *phy = &dev->phy;
106 /* APHY.rev < 5 || GPHY.rev < 6 */
107 static const struct b43_rfatt rfatt_0[] = {
108 {.att = 3,.with_padmix = 0,},
109 {.att = 1,.with_padmix = 0,},
110 {.att = 5,.with_padmix = 0,},
111 {.att = 7,.with_padmix = 0,},
112 {.att = 9,.with_padmix = 0,},
113 {.att = 2,.with_padmix = 0,},
114 {.att = 0,.with_padmix = 0,},
115 {.att = 4,.with_padmix = 0,},
116 {.att = 6,.with_padmix = 0,},
117 {.att = 8,.with_padmix = 0,},
118 {.att = 1,.with_padmix = 1,},
119 {.att = 2,.with_padmix = 1,},
120 {.att = 3,.with_padmix = 1,},
121 {.att = 4,.with_padmix = 1,},
123 /* Radio.rev == 8 && Radio.version == 0x2050 */
124 static const struct b43_rfatt rfatt_1[] = {
125 {.att = 2,.with_padmix = 1,},
126 {.att = 4,.with_padmix = 1,},
127 {.att = 6,.with_padmix = 1,},
128 {.att = 8,.with_padmix = 1,},
129 {.att = 10,.with_padmix = 1,},
130 {.att = 12,.with_padmix = 1,},
131 {.att = 14,.with_padmix = 1,},
134 static const struct b43_rfatt rfatt_2[] = {
135 {.att = 0,.with_padmix = 1,},
136 {.att = 2,.with_padmix = 1,},
137 {.att = 4,.with_padmix = 1,},
138 {.att = 6,.with_padmix = 1,},
139 {.att = 8,.with_padmix = 1,},
140 {.att = 9,.with_padmix = 1,},
141 {.att = 9,.with_padmix = 1,},
144 if ((phy->type == B43_PHYTYPE_A && phy->rev < 5) ||
145 (phy->type == B43_PHYTYPE_G && phy->rev < 6)) {
147 list->list = rfatt_0;
148 list->len = ARRAY_SIZE(rfatt_0);
153 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
155 list->list = rfatt_1;
156 list->len = ARRAY_SIZE(rfatt_1);
162 list->list = rfatt_2;
163 list->len = ARRAY_SIZE(rfatt_2);
168 static void generate_bbatt_list(struct b43_wldev *dev,
169 struct b43_bbatt_list *list)
171 static const struct b43_bbatt bbatt_0[] = {
183 list->list = bbatt_0;
184 list->len = ARRAY_SIZE(bbatt_0);
189 bool b43_has_hardware_pctl(struct b43_phy *phy)
191 if (!phy->hardware_power_control)
208 static void b43_shm_clear_tssi(struct b43_wldev *dev)
210 struct b43_phy *phy = &dev->phy;
214 b43_shm_write16(dev, B43_SHM_SHARED, 0x0068, 0x7F7F);
215 b43_shm_write16(dev, B43_SHM_SHARED, 0x006a, 0x7F7F);
219 b43_shm_write16(dev, B43_SHM_SHARED, 0x0058, 0x7F7F);
220 b43_shm_write16(dev, B43_SHM_SHARED, 0x005a, 0x7F7F);
221 b43_shm_write16(dev, B43_SHM_SHARED, 0x0070, 0x7F7F);
222 b43_shm_write16(dev, B43_SHM_SHARED, 0x0072, 0x7F7F);
227 void b43_raw_phy_lock(struct b43_wldev *dev)
229 struct b43_phy *phy = &dev->phy;
231 B43_WARN_ON(!irqs_disabled());
233 /* We had a check for MACCTL==0 here, but I think that doesn't
234 * make sense, as MACCTL is never 0 when this is called.
236 B43_WARN_ON(b43_read32(dev, B43_MMIO_MACCTL) == 0);
238 if (dev->dev->id.revision < 3) {
239 b43_mac_suspend(dev);
240 spin_lock(&phy->lock);
242 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
243 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
248 void b43_raw_phy_unlock(struct b43_wldev *dev)
250 struct b43_phy *phy = &dev->phy;
252 B43_WARN_ON(!irqs_disabled());
253 if (dev->dev->id.revision < 3) {
255 spin_unlock(&phy->lock);
259 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
260 b43_power_saving_ctl_bits(dev, 0);
265 /* Different PHYs require different register routing flags.
266 * This adjusts (and does sanity checks on) the routing flags.
268 static inline u16 adjust_phyreg_for_phytype(struct b43_phy *phy,
269 u16 offset, struct b43_wldev *dev)
271 if (phy->type == B43_PHYTYPE_A) {
272 /* OFDM registers are base-registers for the A-PHY. */
273 offset &= ~B43_PHYROUTE_OFDM_GPHY;
275 if (offset & B43_PHYROUTE_EXT_GPHY) {
276 /* Ext-G registers are only available on G-PHYs */
277 if (phy->type != B43_PHYTYPE_G) {
278 b43dbg(dev->wl, "EXT-G PHY access at "
279 "0x%04X on %u type PHY\n", offset, phy->type);
286 u16 b43_phy_read(struct b43_wldev * dev, u16 offset)
288 struct b43_phy *phy = &dev->phy;
290 offset = adjust_phyreg_for_phytype(phy, offset, dev);
291 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
292 return b43_read16(dev, B43_MMIO_PHY_DATA);
295 void b43_phy_write(struct b43_wldev *dev, u16 offset, u16 val)
297 struct b43_phy *phy = &dev->phy;
299 offset = adjust_phyreg_for_phytype(phy, offset, dev);
300 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
302 b43_write16(dev, B43_MMIO_PHY_DATA, val);
305 static void b43_radio_set_txpower_a(struct b43_wldev *dev, u16 txpower);
307 /* Adjust the transmission power output (G-PHY) */
308 void b43_set_txpower_g(struct b43_wldev *dev,
309 const struct b43_bbatt *bbatt,
310 const struct b43_rfatt *rfatt, u8 tx_control)
312 struct b43_phy *phy = &dev->phy;
313 struct b43_txpower_lo_control *lo = phy->lo_control;
315 u16 tx_bias, tx_magn;
319 tx_bias = lo->tx_bias;
320 tx_magn = lo->tx_magn;
321 if (unlikely(tx_bias == 0xFF))
324 /* Save the values for later */
325 phy->tx_control = tx_control;
326 memcpy(&phy->rfatt, rfatt, sizeof(*rfatt));
327 memcpy(&phy->bbatt, bbatt, sizeof(*bbatt));
329 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
330 b43dbg(dev->wl, "Tuning TX-power to bbatt(%u), "
331 "rfatt(%u), tx_control(0x%02X), "
332 "tx_bias(0x%02X), tx_magn(0x%02X)\n",
333 bb, rf, tx_control, tx_bias, tx_magn);
336 b43_phy_set_baseband_attenuation(dev, bb);
337 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_RFATT, rf);
338 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
339 b43_radio_write16(dev, 0x43,
340 (rf & 0x000F) | (tx_control & 0x0070));
342 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
343 & 0xFFF0) | (rf & 0x000F));
344 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
345 & ~0x0070) | (tx_control &
348 if (has_tx_magnification(phy)) {
349 b43_radio_write16(dev, 0x52, tx_magn | tx_bias);
351 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
352 & 0xFFF0) | (tx_bias & 0x000F));
354 if (phy->type == B43_PHYTYPE_G)
355 b43_lo_g_adjust(dev);
358 static void default_baseband_attenuation(struct b43_wldev *dev,
359 struct b43_bbatt *bb)
361 struct b43_phy *phy = &dev->phy;
363 if (phy->radio_ver == 0x2050 && phy->radio_rev < 6)
369 static void default_radio_attenuation(struct b43_wldev *dev,
370 struct b43_rfatt *rf)
372 struct ssb_bus *bus = dev->dev->bus;
373 struct b43_phy *phy = &dev->phy;
377 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM &&
378 bus->boardinfo.type == SSB_BOARD_BCM4309G) {
379 if (bus->boardinfo.rev < 0x43) {
382 } else if (bus->boardinfo.rev < 0x51) {
388 if (phy->type == B43_PHYTYPE_A) {
393 switch (phy->radio_ver) {
395 switch (phy->radio_rev) {
402 switch (phy->radio_rev) {
407 if (phy->type == B43_PHYTYPE_G) {
408 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
409 && bus->boardinfo.type == SSB_BOARD_BCM4309G
410 && bus->boardinfo.rev >= 30)
412 else if (bus->boardinfo.vendor ==
414 && bus->boardinfo.type ==
420 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
421 && bus->boardinfo.type == SSB_BOARD_BCM4309G
422 && bus->boardinfo.rev >= 30)
429 if (phy->type == B43_PHYTYPE_G) {
430 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
431 && bus->boardinfo.type == SSB_BOARD_BCM4309G
432 && bus->boardinfo.rev >= 30)
434 else if (bus->boardinfo.vendor ==
436 && bus->boardinfo.type ==
439 else if (bus->chip_id == 0x4320)
470 static u16 default_tx_control(struct b43_wldev *dev)
472 struct b43_phy *phy = &dev->phy;
474 if (phy->radio_ver != 0x2050)
476 if (phy->radio_rev == 1)
477 return B43_TXCTL_PA2DB | B43_TXCTL_TXMIX;
478 if (phy->radio_rev < 6)
479 return B43_TXCTL_PA2DB;
480 if (phy->radio_rev == 8)
481 return B43_TXCTL_TXMIX;
485 /* This func is called "PHY calibrate" in the specs... */
486 void b43_phy_early_init(struct b43_wldev *dev)
488 struct b43_phy *phy = &dev->phy;
489 struct b43_txpower_lo_control *lo = phy->lo_control;
491 default_baseband_attenuation(dev, &phy->bbatt);
492 default_radio_attenuation(dev, &phy->rfatt);
493 phy->tx_control = (default_tx_control(dev) << 4);
495 /* Commit previous writes */
496 b43_read32(dev, B43_MMIO_MACCTL);
498 if (phy->type == B43_PHYTYPE_B || phy->type == B43_PHYTYPE_G) {
499 generate_rfatt_list(dev, &lo->rfatt_list);
500 generate_bbatt_list(dev, &lo->bbatt_list);
502 if (phy->type == B43_PHYTYPE_G && phy->rev == 1) {
503 /* Workaround: Temporarly disable gmode through the early init
504 * phase, as the gmode stuff is not needed for phy rev 1 */
506 b43_wireless_core_reset(dev, 0);
509 b43_wireless_core_reset(dev, B43_TMSLOW_GMODE);
513 /* GPHY_TSSI_Power_Lookup_Table_Init */
514 static void b43_gphy_tssi_power_lt_init(struct b43_wldev *dev)
516 struct b43_phy *phy = &dev->phy;
520 for (i = 0; i < 32; i++)
521 b43_ofdmtab_write16(dev, 0x3C20, i, phy->tssi2dbm[i]);
522 for (i = 32; i < 64; i++)
523 b43_ofdmtab_write16(dev, 0x3C00, i - 32, phy->tssi2dbm[i]);
524 for (i = 0; i < 64; i += 2) {
525 value = (u16) phy->tssi2dbm[i];
526 value |= ((u16) phy->tssi2dbm[i + 1]) << 8;
527 b43_phy_write(dev, 0x380 + (i / 2), value);
531 /* GPHY_Gain_Lookup_Table_Init */
532 static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
534 struct b43_phy *phy = &dev->phy;
535 struct b43_txpower_lo_control *lo = phy->lo_control;
540 if (!lo->lo_measured) {
541 b43_phy_write(dev, 0x3FF, 0);
545 for (rf = 0; rf < lo->rfatt_list.len; rf++) {
546 for (bb = 0; bb < lo->bbatt_list.len; bb++) {
547 if (nr_written >= 0x40)
549 tmp = lo->bbatt_list.list[bb].att;
551 if (phy->radio_rev == 8)
555 tmp |= lo->rfatt_list.list[rf].att;
556 b43_phy_write(dev, 0x3C0 + nr_written, tmp);
562 /* GPHY_DC_Lookup_Table */
563 void b43_gphy_dc_lt_init(struct b43_wldev *dev)
565 struct b43_phy *phy = &dev->phy;
566 struct b43_txpower_lo_control *lo = phy->lo_control;
567 struct b43_loctl *loctl0;
568 struct b43_loctl *loctl1;
570 int rf_offset, bb_offset;
573 for (i = 0; i < lo->rfatt_list.len + lo->bbatt_list.len; i += 2) {
574 rf_offset = i / lo->rfatt_list.len;
575 bb_offset = i % lo->rfatt_list.len;
577 loctl0 = b43_get_lo_g_ctl(dev, &lo->rfatt_list.list[rf_offset],
578 &lo->bbatt_list.list[bb_offset]);
579 if (i + 1 < lo->rfatt_list.len * lo->bbatt_list.len) {
580 rf_offset = (i + 1) / lo->rfatt_list.len;
581 bb_offset = (i + 1) % lo->rfatt_list.len;
584 b43_get_lo_g_ctl(dev,
585 &lo->rfatt_list.list[rf_offset],
586 &lo->bbatt_list.list[bb_offset]);
590 tmp = ((u16) loctl0->q & 0xF);
591 tmp |= ((u16) loctl0->i & 0xF) << 4;
592 tmp |= ((u16) loctl1->q & 0xF) << 8;
593 tmp |= ((u16) loctl1->i & 0xF) << 12; //FIXME?
594 b43_phy_write(dev, 0x3A0 + (i / 2), tmp);
598 static void hardware_pctl_init_aphy(struct b43_wldev *dev)
603 static void hardware_pctl_init_gphy(struct b43_wldev *dev)
605 struct b43_phy *phy = &dev->phy;
607 b43_phy_write(dev, 0x0036, (b43_phy_read(dev, 0x0036) & 0xFFC0)
608 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
609 b43_phy_write(dev, 0x0478, (b43_phy_read(dev, 0x0478) & 0xFF00)
610 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
611 b43_gphy_tssi_power_lt_init(dev);
612 b43_gphy_gain_lt_init(dev);
613 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) & 0xFFBF);
614 b43_phy_write(dev, 0x0014, 0x0000);
616 B43_WARN_ON(phy->rev < 6);
617 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
619 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
621 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801)
624 b43_gphy_dc_lt_init(dev);
627 /* HardwarePowerControl init for A and G PHY */
628 static void b43_hardware_pctl_init(struct b43_wldev *dev)
630 struct b43_phy *phy = &dev->phy;
632 if (!b43_has_hardware_pctl(phy)) {
633 /* No hardware power control */
634 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_HWPCTL);
637 /* Init the hwpctl related hardware */
640 hardware_pctl_init_aphy(dev);
643 hardware_pctl_init_gphy(dev);
648 /* Enable hardware pctl in firmware. */
649 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL);
652 static void b43_hardware_pctl_early_init(struct b43_wldev *dev)
654 struct b43_phy *phy = &dev->phy;
656 if (!b43_has_hardware_pctl(phy)) {
657 b43_phy_write(dev, 0x047A, 0xC111);
661 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036) & 0xFEFF);
662 b43_phy_write(dev, 0x002F, 0x0202);
663 b43_phy_write(dev, 0x047C, b43_phy_read(dev, 0x047C) | 0x0002);
664 b43_phy_write(dev, 0x047A, b43_phy_read(dev, 0x047A) | 0xF000);
665 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
666 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
668 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
670 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
672 b43_phy_write(dev, 0x002E, 0xC07F);
673 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
676 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
678 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
680 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
682 b43_phy_write(dev, 0x004F, b43_phy_read(dev, 0x004F)
684 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
686 b43_phy_write(dev, 0x002E, 0xC07F);
687 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
692 /* Intialize B/G PHY power control
693 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
695 static void b43_phy_init_pctl(struct b43_wldev *dev)
697 struct ssb_bus *bus = dev->dev->bus;
698 struct b43_phy *phy = &dev->phy;
699 struct b43_rfatt old_rfatt;
700 struct b43_bbatt old_bbatt;
701 u8 old_tx_control = 0;
703 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
704 (bus->boardinfo.type == SSB_BOARD_BU4306))
707 b43_phy_write(dev, 0x0028, 0x8018);
709 /* This does something with the Analog... */
710 b43_write16(dev, B43_MMIO_PHY0, b43_read16(dev, B43_MMIO_PHY0)
713 if (phy->type == B43_PHYTYPE_G && !phy->gmode)
715 b43_hardware_pctl_early_init(dev);
716 if (phy->cur_idle_tssi == 0) {
717 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
718 b43_radio_write16(dev, 0x0076,
719 (b43_radio_read16(dev, 0x0076)
722 struct b43_rfatt rfatt;
723 struct b43_bbatt bbatt;
725 memcpy(&old_rfatt, &phy->rfatt, sizeof(old_rfatt));
726 memcpy(&old_bbatt, &phy->bbatt, sizeof(old_bbatt));
727 old_tx_control = phy->tx_control;
730 if (phy->radio_rev == 8) {
732 rfatt.with_padmix = 1;
735 rfatt.with_padmix = 0;
737 b43_set_txpower_g(dev, &bbatt, &rfatt, 0);
739 b43_dummy_transmission(dev);
740 phy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_ITSSI);
742 /* Current-Idle-TSSI sanity check. */
743 if (abs(phy->cur_idle_tssi - phy->tgt_idle_tssi) >= 20) {
745 "!WARNING! Idle-TSSI phy->cur_idle_tssi "
746 "measuring failed. (cur=%d, tgt=%d). Disabling TX power "
747 "adjustment.\n", phy->cur_idle_tssi,
749 phy->cur_idle_tssi = 0;
752 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
753 b43_radio_write16(dev, 0x0076,
754 b43_radio_read16(dev, 0x0076)
757 b43_set_txpower_g(dev, &old_bbatt,
758 &old_rfatt, old_tx_control);
761 b43_hardware_pctl_init(dev);
762 b43_shm_clear_tssi(dev);
765 static void b43_phy_agcsetup(struct b43_wldev *dev)
767 struct b43_phy *phy = &dev->phy;
773 b43_ofdmtab_write16(dev, offset, 0, 0x00FE);
774 b43_ofdmtab_write16(dev, offset, 1, 0x000D);
775 b43_ofdmtab_write16(dev, offset, 2, 0x0013);
776 b43_ofdmtab_write16(dev, offset, 3, 0x0019);
779 b43_ofdmtab_write16(dev, 0x1800, 0, 0x2710);
780 b43_ofdmtab_write16(dev, 0x1801, 0, 0x9B83);
781 b43_ofdmtab_write16(dev, 0x1802, 0, 0x9B83);
782 b43_ofdmtab_write16(dev, 0x1803, 0, 0x0F8D);
783 b43_phy_write(dev, 0x0455, 0x0004);
786 b43_phy_write(dev, 0x04A5, (b43_phy_read(dev, 0x04A5)
788 b43_phy_write(dev, 0x041A, (b43_phy_read(dev, 0x041A)
790 b43_phy_write(dev, 0x041A, (b43_phy_read(dev, 0x041A)
792 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
795 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
798 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
800 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
802 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
804 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
808 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
812 b43_phy_write(dev, 0x0488, (b43_phy_read(dev, 0x0488)
814 b43_phy_write(dev, 0x0488, (b43_phy_read(dev, 0x0488)
816 b43_phy_write(dev, 0x0496, (b43_phy_read(dev, 0x0496)
818 b43_phy_write(dev, 0x0489, (b43_phy_read(dev, 0x0489)
820 b43_phy_write(dev, 0x0489, (b43_phy_read(dev, 0x0489)
822 b43_phy_write(dev, 0x0482, (b43_phy_read(dev, 0x0482)
824 b43_phy_write(dev, 0x0496, (b43_phy_read(dev, 0x0496)
826 b43_phy_write(dev, 0x0481, (b43_phy_read(dev, 0x0481)
828 b43_phy_write(dev, 0x0481, (b43_phy_read(dev, 0x0481)
832 b43_phy_write(dev, 0x0430, 0x092B);
833 b43_phy_write(dev, 0x041B, (b43_phy_read(dev, 0x041B)
836 b43_phy_write(dev, 0x041B, b43_phy_read(dev, 0x041B)
838 b43_phy_write(dev, 0x041F, 0x287A);
839 b43_phy_write(dev, 0x0420, (b43_phy_read(dev, 0x0420)
844 b43_phy_write(dev, 0x0422, 0x287A);
845 b43_phy_write(dev, 0x0420, (b43_phy_read(dev, 0x0420)
849 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
851 b43_phy_write(dev, 0x048E, 0x1C00);
856 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
858 b43_phy_write(dev, 0x048B, 0x005E);
859 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
861 b43_phy_write(dev, 0x048D, 0x0002);
863 b43_ofdmtab_write16(dev, offset, 0, 0x00);
864 b43_ofdmtab_write16(dev, offset, 1, 0x07);
865 b43_ofdmtab_write16(dev, offset, 2, 0x10);
866 b43_ofdmtab_write16(dev, offset, 3, 0x1C);
869 b43_phy_write(dev, 0x0426, b43_phy_read(dev, 0x0426)
871 b43_phy_write(dev, 0x0426, b43_phy_read(dev, 0x0426)
876 static void b43_phy_setupg(struct b43_wldev *dev)
878 struct ssb_bus *bus = dev->dev->bus;
879 struct b43_phy *phy = &dev->phy;
882 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
884 b43_phy_write(dev, 0x0406, 0x4F19);
885 b43_phy_write(dev, B43_PHY_G_CRS,
886 (b43_phy_read(dev, B43_PHY_G_CRS) & 0xFC3F) |
888 b43_phy_write(dev, 0x042C, 0x005A);
889 b43_phy_write(dev, 0x0427, 0x001A);
891 for (i = 0; i < B43_TAB_FINEFREQG_SIZE; i++)
892 b43_ofdmtab_write16(dev, 0x5800, i,
893 b43_tab_finefreqg[i]);
894 for (i = 0; i < B43_TAB_NOISEG1_SIZE; i++)
895 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noiseg1[i]);
896 for (i = 0; i < B43_TAB_ROTOR_SIZE; i++)
897 b43_ofdmtab_write16(dev, 0x2000, i, b43_tab_rotor[i]);
899 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
900 b43_nrssi_hw_write(dev, 0xBA98, (s16) 0x7654);
903 b43_phy_write(dev, 0x04C0, 0x1861);
904 b43_phy_write(dev, 0x04C1, 0x0271);
905 } else if (phy->rev > 2) {
906 b43_phy_write(dev, 0x04C0, 0x0098);
907 b43_phy_write(dev, 0x04C1, 0x0070);
908 b43_phy_write(dev, 0x04C9, 0x0080);
910 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x800);
912 for (i = 0; i < 64; i++)
913 b43_ofdmtab_write16(dev, 0x4000, i, i);
914 for (i = 0; i < B43_TAB_NOISEG2_SIZE; i++)
915 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noiseg2[i]);
919 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
920 b43_ofdmtab_write16(dev, 0x1400, i,
921 b43_tab_noisescaleg1[i]);
922 else if ((phy->rev >= 7) && (b43_phy_read(dev, 0x0449) & 0x0200))
923 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
924 b43_ofdmtab_write16(dev, 0x1400, i,
925 b43_tab_noisescaleg3[i]);
927 for (i = 0; i < B43_TAB_NOISESCALEG_SIZE; i++)
928 b43_ofdmtab_write16(dev, 0x1400, i,
929 b43_tab_noisescaleg2[i]);
932 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++)
933 b43_ofdmtab_write16(dev, 0x5000, i,
934 b43_tab_sigmasqr1[i]);
935 else if ((phy->rev > 2) && (phy->rev <= 8))
936 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++)
937 b43_ofdmtab_write16(dev, 0x5000, i,
938 b43_tab_sigmasqr2[i]);
941 for (i = 0; i < B43_TAB_RETARD_SIZE; i++)
942 b43_ofdmtab_write32(dev, 0x2400, i, b43_tab_retard[i]);
943 for (i = 4; i < 20; i++)
944 b43_ofdmtab_write16(dev, 0x5400, i, 0x0020);
945 b43_phy_agcsetup(dev);
947 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
948 (bus->boardinfo.type == SSB_BOARD_BU4306) &&
949 (bus->boardinfo.rev == 0x17))
952 b43_ofdmtab_write16(dev, 0x5001, 0, 0x0002);
953 b43_ofdmtab_write16(dev, 0x5002, 0, 0x0001);
955 for (i = 0; i < 0x20; i++)
956 b43_ofdmtab_write16(dev, 0x1000, i, 0x0820);
957 b43_phy_agcsetup(dev);
958 b43_phy_read(dev, 0x0400); /* dummy read */
959 b43_phy_write(dev, 0x0403, 0x1000);
960 b43_ofdmtab_write16(dev, 0x3C02, 0, 0x000F);
961 b43_ofdmtab_write16(dev, 0x3C03, 0, 0x0014);
963 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
964 (bus->boardinfo.type == SSB_BOARD_BU4306) &&
965 (bus->boardinfo.rev == 0x17))
968 b43_ofdmtab_write16(dev, 0x0401, 0, 0x0002);
969 b43_ofdmtab_write16(dev, 0x0402, 0, 0x0001);
973 /* Initialize the noisescaletable for APHY */
974 static void b43_phy_init_noisescaletbl(struct b43_wldev *dev)
976 struct b43_phy *phy = &dev->phy;
979 for (i = 0; i < 12; i++) {
981 b43_ofdmtab_write16(dev, 0x1400, i, 0x6767);
983 b43_ofdmtab_write16(dev, 0x1400, i, 0x2323);
986 b43_ofdmtab_write16(dev, 0x1400, i, 0x6700);
988 b43_ofdmtab_write16(dev, 0x1400, i, 0x2300);
989 for (i = 0; i < 11; i++) {
991 b43_ofdmtab_write16(dev, 0x1400, i, 0x6767);
993 b43_ofdmtab_write16(dev, 0x1400, i, 0x2323);
996 b43_ofdmtab_write16(dev, 0x1400, i, 0x0067);
998 b43_ofdmtab_write16(dev, 0x1400, i, 0x0023);
1001 static void b43_phy_setupa(struct b43_wldev *dev)
1003 struct b43_phy *phy = &dev->phy;
1006 B43_WARN_ON(phy->type != B43_PHYTYPE_A);
1009 b43_phy_write(dev, 0x008E, 0x3800);
1010 b43_phy_write(dev, 0x0035, 0x03FF);
1011 b43_phy_write(dev, 0x0036, 0x0400);
1013 b43_ofdmtab_write16(dev, 0x3807, 0, 0x0051);
1015 b43_phy_write(dev, 0x001C, 0x0FF9);
1016 b43_phy_write(dev, 0x0020, b43_phy_read(dev, 0x0020) & 0xFF0F);
1017 b43_ofdmtab_write16(dev, 0x3C0C, 0, 0x07BF);
1018 b43_radio_write16(dev, 0x0002, 0x07BF);
1020 b43_phy_write(dev, 0x0024, 0x4680);
1021 b43_phy_write(dev, 0x0020, 0x0003);
1022 b43_phy_write(dev, 0x001D, 0x0F40);
1023 b43_phy_write(dev, 0x001F, 0x1C00);
1025 b43_phy_write(dev, 0x002A, (b43_phy_read(dev, 0x002A)
1026 & 0x00FF) | 0x0400);
1027 b43_phy_write(dev, 0x002B, b43_phy_read(dev, 0x002B)
1029 b43_phy_write(dev, 0x008E, 0x58C1);
1031 b43_ofdmtab_write16(dev, 0x0803, 0, 0x000F);
1032 b43_ofdmtab_write16(dev, 0x0804, 0, 0x001F);
1033 b43_ofdmtab_write16(dev, 0x0805, 0, 0x002A);
1034 b43_ofdmtab_write16(dev, 0x0805, 0, 0x0030);
1035 b43_ofdmtab_write16(dev, 0x0807, 0, 0x003A);
1037 b43_ofdmtab_write16(dev, 0x0000, 0, 0x0013);
1038 b43_ofdmtab_write16(dev, 0x0000, 1, 0x0013);
1039 b43_ofdmtab_write16(dev, 0x0000, 2, 0x0013);
1040 b43_ofdmtab_write16(dev, 0x0000, 3, 0x0013);
1041 b43_ofdmtab_write16(dev, 0x0000, 4, 0x0015);
1042 b43_ofdmtab_write16(dev, 0x0000, 5, 0x0015);
1043 b43_ofdmtab_write16(dev, 0x0000, 6, 0x0019);
1045 b43_ofdmtab_write16(dev, 0x0404, 0, 0x0003);
1046 b43_ofdmtab_write16(dev, 0x0405, 0, 0x0003);
1047 b43_ofdmtab_write16(dev, 0x0406, 0, 0x0007);
1049 for (i = 0; i < 16; i++)
1050 b43_ofdmtab_write16(dev, 0x4000, i, (0x8 + i) & 0x000F);
1052 b43_ofdmtab_write16(dev, 0x3003, 0, 0x1044);
1053 b43_ofdmtab_write16(dev, 0x3004, 0, 0x7201);
1054 b43_ofdmtab_write16(dev, 0x3006, 0, 0x0040);
1055 b43_ofdmtab_write16(dev, 0x3001, 0,
1056 (b43_ofdmtab_read16(dev, 0x3001, 0) &
1059 for (i = 0; i < B43_TAB_FINEFREQA_SIZE; i++)
1060 b43_ofdmtab_write16(dev, 0x5800, i,
1061 b43_tab_finefreqa[i]);
1062 for (i = 0; i < B43_TAB_NOISEA2_SIZE; i++)
1063 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noisea2[i]);
1064 for (i = 0; i < B43_TAB_ROTOR_SIZE; i++)
1065 b43_ofdmtab_write32(dev, 0x2000, i, b43_tab_rotor[i]);
1066 b43_phy_init_noisescaletbl(dev);
1067 for (i = 0; i < B43_TAB_RETARD_SIZE; i++)
1068 b43_ofdmtab_write32(dev, 0x2400, i, b43_tab_retard[i]);
1071 for (i = 0; i < 64; i++)
1072 b43_ofdmtab_write16(dev, 0x4000, i, i);
1074 b43_ofdmtab_write16(dev, 0x3807, 0, 0x0051);
1076 b43_phy_write(dev, 0x001C, 0x0FF9);
1077 b43_phy_write(dev, 0x0020, b43_phy_read(dev, 0x0020) & 0xFF0F);
1078 b43_radio_write16(dev, 0x0002, 0x07BF);
1080 b43_phy_write(dev, 0x0024, 0x4680);
1081 b43_phy_write(dev, 0x0020, 0x0003);
1082 b43_phy_write(dev, 0x001D, 0x0F40);
1083 b43_phy_write(dev, 0x001F, 0x1C00);
1084 b43_phy_write(dev, 0x002A, (b43_phy_read(dev, 0x002A)
1085 & 0x00FF) | 0x0400);
1087 b43_ofdmtab_write16(dev, 0x3000, 1,
1088 (b43_ofdmtab_read16(dev, 0x3000, 1)
1089 & 0x0010) | 0x0008);
1090 for (i = 0; i < B43_TAB_NOISEA3_SIZE; i++) {
1091 b43_ofdmtab_write16(dev, 0x1800, i, b43_tab_noisea3[i]);
1093 b43_phy_init_noisescaletbl(dev);
1094 for (i = 0; i < B43_TAB_SIGMASQR_SIZE; i++) {
1095 b43_ofdmtab_write16(dev, 0x5000, i,
1096 b43_tab_sigmasqr1[i]);
1099 b43_phy_write(dev, 0x0003, 0x1808);
1101 b43_ofdmtab_write16(dev, 0x0803, 0, 0x000F);
1102 b43_ofdmtab_write16(dev, 0x0804, 0, 0x001F);
1103 b43_ofdmtab_write16(dev, 0x0805, 0, 0x002A);
1104 b43_ofdmtab_write16(dev, 0x0805, 0, 0x0030);
1105 b43_ofdmtab_write16(dev, 0x0807, 0, 0x003A);
1107 b43_ofdmtab_write16(dev, 0x0000, 0, 0x0013);
1108 b43_ofdmtab_write16(dev, 0x0001, 0, 0x0013);
1109 b43_ofdmtab_write16(dev, 0x0002, 0, 0x0013);
1110 b43_ofdmtab_write16(dev, 0x0003, 0, 0x0013);
1111 b43_ofdmtab_write16(dev, 0x0004, 0, 0x0015);
1112 b43_ofdmtab_write16(dev, 0x0005, 0, 0x0015);
1113 b43_ofdmtab_write16(dev, 0x0006, 0, 0x0019);
1115 b43_ofdmtab_write16(dev, 0x0404, 0, 0x0003);
1116 b43_ofdmtab_write16(dev, 0x0405, 0, 0x0003);
1117 b43_ofdmtab_write16(dev, 0x0406, 0, 0x0007);
1119 b43_ofdmtab_write16(dev, 0x3C02, 0, 0x000F);
1120 b43_ofdmtab_write16(dev, 0x3C03, 0, 0x0014);
1127 /* Initialize APHY. This is also called for the GPHY in some cases. */
1128 static void b43_phy_inita(struct b43_wldev *dev)
1130 struct ssb_bus *bus = dev->dev->bus;
1131 struct b43_phy *phy = &dev->phy;
1136 if (phy->type == B43_PHYTYPE_A) {
1137 b43_phy_setupa(dev);
1139 b43_phy_setupg(dev);
1141 (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_PACTRL))
1142 b43_phy_write(dev, 0x046E, 0x03CF);
1146 b43_phy_write(dev, B43_PHY_A_CRS,
1147 (b43_phy_read(dev, B43_PHY_A_CRS) & 0xF83C) | 0x0340);
1148 b43_phy_write(dev, 0x0034, 0x0001);
1151 b43_phy_write(dev, B43_PHY_A_CRS,
1152 b43_phy_read(dev, B43_PHY_A_CRS) | (1 << 14));
1153 b43_radio_init2060(dev);
1155 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1156 ((bus->boardinfo.type == SSB_BOARD_BU4306) ||
1157 (bus->boardinfo.type == SSB_BOARD_BU4309))) {
1158 if (phy->lofcal == 0xFFFF) {
1160 b43_radio_set_tx_iq(dev);
1162 b43_radio_write16(dev, 0x001E, phy->lofcal);
1165 b43_phy_write(dev, 0x007A, 0xF111);
1167 if (phy->cur_idle_tssi == 0) {
1168 b43_radio_write16(dev, 0x0019, 0x0000);
1169 b43_radio_write16(dev, 0x0017, 0x0020);
1171 tval = b43_ofdmtab_read16(dev, 0x3001, 0);
1172 if (phy->rev == 1) {
1173 b43_ofdmtab_write16(dev, 0x3001, 0,
1174 (b43_ofdmtab_read16(dev, 0x3001, 0)
1178 b43_ofdmtab_write16(dev, 0x3001, 0,
1179 (b43_ofdmtab_read16(dev, 0x3001, 0)
1183 b43_dummy_transmission(dev);
1184 phy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_A_PCTL);
1185 b43_ofdmtab_write16(dev, 0x3001, 0, tval);
1187 b43_radio_set_txpower_a(dev, 0x0018);
1189 b43_shm_clear_tssi(dev);
1192 static void b43_phy_initb2(struct b43_wldev *dev)
1194 struct b43_phy *phy = &dev->phy;
1197 b43_write16(dev, 0x03EC, 0x3F22);
1198 b43_phy_write(dev, 0x0020, 0x301C);
1199 b43_phy_write(dev, 0x0026, 0x0000);
1200 b43_phy_write(dev, 0x0030, 0x00C6);
1201 b43_phy_write(dev, 0x0088, 0x3E00);
1203 for (offset = 0x0089; offset < 0x00A7; offset++) {
1204 b43_phy_write(dev, offset, val);
1207 b43_phy_write(dev, 0x03E4, 0x3000);
1208 b43_radio_selectchannel(dev, phy->channel, 0);
1209 if (phy->radio_ver != 0x2050) {
1210 b43_radio_write16(dev, 0x0075, 0x0080);
1211 b43_radio_write16(dev, 0x0079, 0x0081);
1213 b43_radio_write16(dev, 0x0050, 0x0020);
1214 b43_radio_write16(dev, 0x0050, 0x0023);
1215 if (phy->radio_ver == 0x2050) {
1216 b43_radio_write16(dev, 0x0050, 0x0020);
1217 b43_radio_write16(dev, 0x005A, 0x0070);
1218 b43_radio_write16(dev, 0x005B, 0x007B);
1219 b43_radio_write16(dev, 0x005C, 0x00B0);
1220 b43_radio_write16(dev, 0x007A, 0x000F);
1221 b43_phy_write(dev, 0x0038, 0x0677);
1222 b43_radio_init2050(dev);
1224 b43_phy_write(dev, 0x0014, 0x0080);
1225 b43_phy_write(dev, 0x0032, 0x00CA);
1226 b43_phy_write(dev, 0x0032, 0x00CC);
1227 b43_phy_write(dev, 0x0035, 0x07C2);
1228 b43_lo_b_measure(dev);
1229 b43_phy_write(dev, 0x0026, 0xCC00);
1230 if (phy->radio_ver != 0x2050)
1231 b43_phy_write(dev, 0x0026, 0xCE00);
1232 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1000);
1233 b43_phy_write(dev, 0x002A, 0x88A3);
1234 if (phy->radio_ver != 0x2050)
1235 b43_phy_write(dev, 0x002A, 0x88C2);
1236 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1237 b43_phy_init_pctl(dev);
1240 static void b43_phy_initb4(struct b43_wldev *dev)
1242 struct b43_phy *phy = &dev->phy;
1245 b43_write16(dev, 0x03EC, 0x3F22);
1246 b43_phy_write(dev, 0x0020, 0x301C);
1247 b43_phy_write(dev, 0x0026, 0x0000);
1248 b43_phy_write(dev, 0x0030, 0x00C6);
1249 b43_phy_write(dev, 0x0088, 0x3E00);
1251 for (offset = 0x0089; offset < 0x00A7; offset++) {
1252 b43_phy_write(dev, offset, val);
1255 b43_phy_write(dev, 0x03E4, 0x3000);
1256 b43_radio_selectchannel(dev, phy->channel, 0);
1257 if (phy->radio_ver != 0x2050) {
1258 b43_radio_write16(dev, 0x0075, 0x0080);
1259 b43_radio_write16(dev, 0x0079, 0x0081);
1261 b43_radio_write16(dev, 0x0050, 0x0020);
1262 b43_radio_write16(dev, 0x0050, 0x0023);
1263 if (phy->radio_ver == 0x2050) {
1264 b43_radio_write16(dev, 0x0050, 0x0020);
1265 b43_radio_write16(dev, 0x005A, 0x0070);
1266 b43_radio_write16(dev, 0x005B, 0x007B);
1267 b43_radio_write16(dev, 0x005C, 0x00B0);
1268 b43_radio_write16(dev, 0x007A, 0x000F);
1269 b43_phy_write(dev, 0x0038, 0x0677);
1270 b43_radio_init2050(dev);
1272 b43_phy_write(dev, 0x0014, 0x0080);
1273 b43_phy_write(dev, 0x0032, 0x00CA);
1274 if (phy->radio_ver == 0x2050)
1275 b43_phy_write(dev, 0x0032, 0x00E0);
1276 b43_phy_write(dev, 0x0035, 0x07C2);
1278 b43_lo_b_measure(dev);
1280 b43_phy_write(dev, 0x0026, 0xCC00);
1281 if (phy->radio_ver == 0x2050)
1282 b43_phy_write(dev, 0x0026, 0xCE00);
1283 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1100);
1284 b43_phy_write(dev, 0x002A, 0x88A3);
1285 if (phy->radio_ver == 0x2050)
1286 b43_phy_write(dev, 0x002A, 0x88C2);
1287 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1288 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI) {
1289 b43_calc_nrssi_slope(dev);
1290 b43_calc_nrssi_threshold(dev);
1292 b43_phy_init_pctl(dev);
1295 static void b43_phy_initb5(struct b43_wldev *dev)
1297 struct ssb_bus *bus = dev->dev->bus;
1298 struct b43_phy *phy = &dev->phy;
1302 if (phy->analog == 1) {
1303 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
1306 if ((bus->boardinfo.vendor != SSB_BOARDVENDOR_BCM) &&
1307 (bus->boardinfo.type != SSB_BOARD_BU4306)) {
1309 for (offset = 0x00A8; offset < 0x00C7; offset++) {
1310 b43_phy_write(dev, offset, value);
1314 b43_phy_write(dev, 0x0035, (b43_phy_read(dev, 0x0035) & 0xF0FF)
1316 if (phy->radio_ver == 0x2050)
1317 b43_phy_write(dev, 0x0038, 0x0667);
1319 if (phy->gmode || phy->rev >= 2) {
1320 if (phy->radio_ver == 0x2050) {
1321 b43_radio_write16(dev, 0x007A,
1322 b43_radio_read16(dev, 0x007A)
1324 b43_radio_write16(dev, 0x0051,
1325 b43_radio_read16(dev, 0x0051)
1328 b43_write16(dev, B43_MMIO_PHY_RADIO, 0x0000);
1330 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1331 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1333 b43_phy_write(dev, 0x001C, 0x186A);
1335 b43_phy_write(dev, 0x0013,
1336 (b43_phy_read(dev, 0x0013) & 0x00FF) | 0x1900);
1337 b43_phy_write(dev, 0x0035,
1338 (b43_phy_read(dev, 0x0035) & 0xFFC0) | 0x0064);
1339 b43_phy_write(dev, 0x005D,
1340 (b43_phy_read(dev, 0x005D) & 0xFF80) | 0x000A);
1343 if (dev->bad_frames_preempt) {
1344 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
1346 B43_PHY_RADIO_BITFIELD) | (1 << 11));
1349 if (phy->analog == 1) {
1350 b43_phy_write(dev, 0x0026, 0xCE00);
1351 b43_phy_write(dev, 0x0021, 0x3763);
1352 b43_phy_write(dev, 0x0022, 0x1BC3);
1353 b43_phy_write(dev, 0x0023, 0x06F9);
1354 b43_phy_write(dev, 0x0024, 0x037E);
1356 b43_phy_write(dev, 0x0026, 0xCC00);
1357 b43_phy_write(dev, 0x0030, 0x00C6);
1358 b43_write16(dev, 0x03EC, 0x3F22);
1360 if (phy->analog == 1)
1361 b43_phy_write(dev, 0x0020, 0x3E1C);
1363 b43_phy_write(dev, 0x0020, 0x301C);
1365 if (phy->analog == 0)
1366 b43_write16(dev, 0x03E4, 0x3000);
1368 old_channel = phy->channel;
1369 /* Force to channel 7, even if not supported. */
1370 b43_radio_selectchannel(dev, 7, 0);
1372 if (phy->radio_ver != 0x2050) {
1373 b43_radio_write16(dev, 0x0075, 0x0080);
1374 b43_radio_write16(dev, 0x0079, 0x0081);
1377 b43_radio_write16(dev, 0x0050, 0x0020);
1378 b43_radio_write16(dev, 0x0050, 0x0023);
1380 if (phy->radio_ver == 0x2050) {
1381 b43_radio_write16(dev, 0x0050, 0x0020);
1382 b43_radio_write16(dev, 0x005A, 0x0070);
1385 b43_radio_write16(dev, 0x005B, 0x007B);
1386 b43_radio_write16(dev, 0x005C, 0x00B0);
1388 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0007);
1390 b43_radio_selectchannel(dev, old_channel, 0);
1392 b43_phy_write(dev, 0x0014, 0x0080);
1393 b43_phy_write(dev, 0x0032, 0x00CA);
1394 b43_phy_write(dev, 0x002A, 0x88A3);
1396 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1398 if (phy->radio_ver == 0x2050)
1399 b43_radio_write16(dev, 0x005D, 0x000D);
1401 b43_write16(dev, 0x03E4, (b43_read16(dev, 0x03E4) & 0xFFC0) | 0x0004);
1404 static void b43_phy_initb6(struct b43_wldev *dev)
1406 struct b43_phy *phy = &dev->phy;
1410 b43_phy_write(dev, 0x003E, 0x817A);
1411 b43_radio_write16(dev, 0x007A,
1412 (b43_radio_read16(dev, 0x007A) | 0x0058));
1413 if (phy->radio_rev == 4 || phy->radio_rev == 5) {
1414 b43_radio_write16(dev, 0x51, 0x37);
1415 b43_radio_write16(dev, 0x52, 0x70);
1416 b43_radio_write16(dev, 0x53, 0xB3);
1417 b43_radio_write16(dev, 0x54, 0x9B);
1418 b43_radio_write16(dev, 0x5A, 0x88);
1419 b43_radio_write16(dev, 0x5B, 0x88);
1420 b43_radio_write16(dev, 0x5D, 0x88);
1421 b43_radio_write16(dev, 0x5E, 0x88);
1422 b43_radio_write16(dev, 0x7D, 0x88);
1423 b43_hf_write(dev, b43_hf_read(dev)
1424 | B43_HF_TSSIRPSMW);
1426 B43_WARN_ON(phy->radio_rev == 6 || phy->radio_rev == 7); /* We had code for these revs here... */
1427 if (phy->radio_rev == 8) {
1428 b43_radio_write16(dev, 0x51, 0);
1429 b43_radio_write16(dev, 0x52, 0x40);
1430 b43_radio_write16(dev, 0x53, 0xB7);
1431 b43_radio_write16(dev, 0x54, 0x98);
1432 b43_radio_write16(dev, 0x5A, 0x88);
1433 b43_radio_write16(dev, 0x5B, 0x6B);
1434 b43_radio_write16(dev, 0x5C, 0x0F);
1435 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_ALTIQ) {
1436 b43_radio_write16(dev, 0x5D, 0xFA);
1437 b43_radio_write16(dev, 0x5E, 0xD8);
1439 b43_radio_write16(dev, 0x5D, 0xF5);
1440 b43_radio_write16(dev, 0x5E, 0xB8);
1442 b43_radio_write16(dev, 0x0073, 0x0003);
1443 b43_radio_write16(dev, 0x007D, 0x00A8);
1444 b43_radio_write16(dev, 0x007C, 0x0001);
1445 b43_radio_write16(dev, 0x007E, 0x0008);
1448 for (offset = 0x0088; offset < 0x0098; offset++) {
1449 b43_phy_write(dev, offset, val);
1453 for (offset = 0x0098; offset < 0x00A8; offset++) {
1454 b43_phy_write(dev, offset, val);
1458 for (offset = 0x00A8; offset < 0x00C8; offset++) {
1459 b43_phy_write(dev, offset, (val & 0x3F3F));
1462 if (phy->type == B43_PHYTYPE_G) {
1463 b43_radio_write16(dev, 0x007A,
1464 b43_radio_read16(dev, 0x007A) | 0x0020);
1465 b43_radio_write16(dev, 0x0051,
1466 b43_radio_read16(dev, 0x0051) | 0x0004);
1467 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1468 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1469 b43_phy_write(dev, 0x5B, 0);
1470 b43_phy_write(dev, 0x5C, 0);
1473 old_channel = phy->channel;
1474 if (old_channel >= 8)
1475 b43_radio_selectchannel(dev, 1, 0);
1477 b43_radio_selectchannel(dev, 13, 0);
1479 b43_radio_write16(dev, 0x0050, 0x0020);
1480 b43_radio_write16(dev, 0x0050, 0x0023);
1482 if (phy->radio_rev < 6 || phy->radio_rev == 8) {
1483 b43_radio_write16(dev, 0x7C, (b43_radio_read16(dev, 0x7C)
1485 b43_radio_write16(dev, 0x50, 0x20);
1487 if (phy->radio_rev <= 2) {
1488 b43_radio_write16(dev, 0x7C, 0x20);
1489 b43_radio_write16(dev, 0x5A, 0x70);
1490 b43_radio_write16(dev, 0x5B, 0x7B);
1491 b43_radio_write16(dev, 0x5C, 0xB0);
1493 b43_radio_write16(dev, 0x007A,
1494 (b43_radio_read16(dev, 0x007A) & 0x00F8) | 0x0007);
1496 b43_radio_selectchannel(dev, old_channel, 0);
1498 b43_phy_write(dev, 0x0014, 0x0200);
1499 if (phy->radio_rev >= 6)
1500 b43_phy_write(dev, 0x2A, 0x88C2);
1502 b43_phy_write(dev, 0x2A, 0x8AC0);
1503 b43_phy_write(dev, 0x0038, 0x0668);
1504 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1505 if (phy->radio_rev <= 5) {
1506 b43_phy_write(dev, 0x5D, (b43_phy_read(dev, 0x5D)
1507 & 0xFF80) | 0x0003);
1509 if (phy->radio_rev <= 2)
1510 b43_radio_write16(dev, 0x005D, 0x000D);
1512 if (phy->analog == 4) {
1513 b43_write16(dev, 0x3E4, 9);
1514 b43_phy_write(dev, 0x61, b43_phy_read(dev, 0x61)
1517 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0)
1520 if (phy->type == B43_PHYTYPE_B) {
1521 b43_write16(dev, 0x03E6, 0x8140);
1522 b43_phy_write(dev, 0x0016, 0x0410);
1523 b43_phy_write(dev, 0x0017, 0x0820);
1524 b43_phy_write(dev, 0x0062, 0x0007);
1525 b43_radio_init2050(dev);
1526 b43_lo_g_measure(dev);
1527 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI) {
1528 b43_calc_nrssi_slope(dev);
1529 b43_calc_nrssi_threshold(dev);
1531 b43_phy_init_pctl(dev);
1532 } else if (phy->type == B43_PHYTYPE_G)
1533 b43_write16(dev, 0x03E6, 0x0);
1536 static void b43_calc_loopback_gain(struct b43_wldev *dev)
1538 struct b43_phy *phy = &dev->phy;
1539 u16 backup_phy[16] = { 0 };
1540 u16 backup_radio[3];
1542 u16 i, j, loop_i_max;
1544 u16 loop1_outer_done, loop1_inner_done;
1546 backup_phy[0] = b43_phy_read(dev, B43_PHY_CRS0);
1547 backup_phy[1] = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
1548 backup_phy[2] = b43_phy_read(dev, B43_PHY_RFOVER);
1549 backup_phy[3] = b43_phy_read(dev, B43_PHY_RFOVERVAL);
1550 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1551 backup_phy[4] = b43_phy_read(dev, B43_PHY_ANALOGOVER);
1552 backup_phy[5] = b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
1554 backup_phy[6] = b43_phy_read(dev, B43_PHY_BASE(0x5A));
1555 backup_phy[7] = b43_phy_read(dev, B43_PHY_BASE(0x59));
1556 backup_phy[8] = b43_phy_read(dev, B43_PHY_BASE(0x58));
1557 backup_phy[9] = b43_phy_read(dev, B43_PHY_BASE(0x0A));
1558 backup_phy[10] = b43_phy_read(dev, B43_PHY_BASE(0x03));
1559 backup_phy[11] = b43_phy_read(dev, B43_PHY_LO_MASK);
1560 backup_phy[12] = b43_phy_read(dev, B43_PHY_LO_CTL);
1561 backup_phy[13] = b43_phy_read(dev, B43_PHY_BASE(0x2B));
1562 backup_phy[14] = b43_phy_read(dev, B43_PHY_PGACTL);
1563 backup_phy[15] = b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
1564 backup_bband = phy->bbatt.att;
1565 backup_radio[0] = b43_radio_read16(dev, 0x52);
1566 backup_radio[1] = b43_radio_read16(dev, 0x43);
1567 backup_radio[2] = b43_radio_read16(dev, 0x7A);
1569 b43_phy_write(dev, B43_PHY_CRS0,
1570 b43_phy_read(dev, B43_PHY_CRS0) & 0x3FFF);
1571 b43_phy_write(dev, B43_PHY_CCKBBANDCFG,
1572 b43_phy_read(dev, B43_PHY_CCKBBANDCFG) | 0x8000);
1573 b43_phy_write(dev, B43_PHY_RFOVER,
1574 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0002);
1575 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1576 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFD);
1577 b43_phy_write(dev, B43_PHY_RFOVER,
1578 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0001);
1579 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1580 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFE);
1581 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1582 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1583 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0001);
1584 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1586 B43_PHY_ANALOGOVERVAL) & 0xFFFE);
1587 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1588 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0002);
1589 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1591 B43_PHY_ANALOGOVERVAL) & 0xFFFD);
1593 b43_phy_write(dev, B43_PHY_RFOVER,
1594 b43_phy_read(dev, B43_PHY_RFOVER) | 0x000C);
1595 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1596 b43_phy_read(dev, B43_PHY_RFOVERVAL) | 0x000C);
1597 b43_phy_write(dev, B43_PHY_RFOVER,
1598 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0030);
1599 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1600 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1603 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0780);
1604 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
1605 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
1607 b43_phy_write(dev, B43_PHY_BASE(0x0A),
1608 b43_phy_read(dev, B43_PHY_BASE(0x0A)) | 0x2000);
1609 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1610 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1611 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0004);
1612 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1614 B43_PHY_ANALOGOVERVAL) & 0xFFFB);
1616 b43_phy_write(dev, B43_PHY_BASE(0x03),
1617 (b43_phy_read(dev, B43_PHY_BASE(0x03))
1620 if (phy->radio_rev == 8) {
1621 b43_radio_write16(dev, 0x43, 0x000F);
1623 b43_radio_write16(dev, 0x52, 0);
1624 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
1627 b43_phy_set_baseband_attenuation(dev, 11);
1630 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
1632 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
1633 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
1635 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1636 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1638 b43_phy_write(dev, B43_PHY_BASE(0x2B),
1639 (b43_phy_read(dev, B43_PHY_BASE(0x2B))
1642 b43_phy_write(dev, B43_PHY_RFOVER,
1643 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0100);
1644 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1645 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xCFFF);
1647 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_EXTLNA) {
1648 if (phy->rev >= 7) {
1649 b43_phy_write(dev, B43_PHY_RFOVER,
1650 b43_phy_read(dev, B43_PHY_RFOVER)
1652 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1653 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1657 b43_radio_write16(dev, 0x7A, b43_radio_read16(dev, 0x7A)
1661 loop_i_max = (phy->radio_rev == 8) ? 15 : 9;
1662 for (i = 0; i < loop_i_max; i++) {
1663 for (j = 0; j < 16; j++) {
1664 b43_radio_write16(dev, 0x43, i);
1665 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1666 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1667 & 0xF0FF) | (j << 8));
1668 b43_phy_write(dev, B43_PHY_PGACTL,
1669 (b43_phy_read(dev, B43_PHY_PGACTL)
1670 & 0x0FFF) | 0xA000);
1671 b43_phy_write(dev, B43_PHY_PGACTL,
1672 b43_phy_read(dev, B43_PHY_PGACTL)
1675 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1680 loop1_outer_done = i;
1681 loop1_inner_done = j;
1683 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1684 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1687 for (j = j - 8; j < 16; j++) {
1688 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1689 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1690 & 0xF0FF) | (j << 8));
1691 b43_phy_write(dev, B43_PHY_PGACTL,
1692 (b43_phy_read(dev, B43_PHY_PGACTL)
1693 & 0x0FFF) | 0xA000);
1694 b43_phy_write(dev, B43_PHY_PGACTL,
1695 b43_phy_read(dev, B43_PHY_PGACTL)
1699 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1706 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1707 b43_phy_write(dev, B43_PHY_ANALOGOVER, backup_phy[4]);
1708 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, backup_phy[5]);
1710 b43_phy_write(dev, B43_PHY_BASE(0x5A), backup_phy[6]);
1711 b43_phy_write(dev, B43_PHY_BASE(0x59), backup_phy[7]);
1712 b43_phy_write(dev, B43_PHY_BASE(0x58), backup_phy[8]);
1713 b43_phy_write(dev, B43_PHY_BASE(0x0A), backup_phy[9]);
1714 b43_phy_write(dev, B43_PHY_BASE(0x03), backup_phy[10]);
1715 b43_phy_write(dev, B43_PHY_LO_MASK, backup_phy[11]);
1716 b43_phy_write(dev, B43_PHY_LO_CTL, backup_phy[12]);
1717 b43_phy_write(dev, B43_PHY_BASE(0x2B), backup_phy[13]);
1718 b43_phy_write(dev, B43_PHY_PGACTL, backup_phy[14]);
1720 b43_phy_set_baseband_attenuation(dev, backup_bband);
1722 b43_radio_write16(dev, 0x52, backup_radio[0]);
1723 b43_radio_write16(dev, 0x43, backup_radio[1]);
1724 b43_radio_write16(dev, 0x7A, backup_radio[2]);
1726 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2] | 0x0003);
1728 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2]);
1729 b43_phy_write(dev, B43_PHY_RFOVERVAL, backup_phy[3]);
1730 b43_phy_write(dev, B43_PHY_CRS0, backup_phy[0]);
1731 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, backup_phy[1]);
1734 ((loop1_inner_done * 6) - (loop1_outer_done * 4)) - 11;
1735 phy->trsw_rx_gain = trsw_rx * 2;
1738 static void b43_phy_initg(struct b43_wldev *dev)
1740 struct b43_phy *phy = &dev->phy;
1744 b43_phy_initb5(dev);
1746 b43_phy_initb6(dev);
1748 if (phy->rev >= 2 || phy->gmode)
1751 if (phy->rev >= 2) {
1752 b43_phy_write(dev, B43_PHY_ANALOGOVER, 0);
1753 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, 0);
1755 if (phy->rev == 2) {
1756 b43_phy_write(dev, B43_PHY_RFOVER, 0);
1757 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1760 b43_phy_write(dev, B43_PHY_RFOVER, 0x400);
1761 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1763 if (phy->gmode || phy->rev >= 2) {
1764 tmp = b43_phy_read(dev, B43_PHY_VERSION_OFDM);
1765 tmp &= B43_PHYVER_VERSION;
1766 if (tmp == 3 || tmp == 5) {
1767 b43_phy_write(dev, B43_PHY_OFDM(0xC2), 0x1816);
1768 b43_phy_write(dev, B43_PHY_OFDM(0xC3), 0x8006);
1771 b43_phy_write(dev, B43_PHY_OFDM(0xCC),
1772 (b43_phy_read(dev, B43_PHY_OFDM(0xCC))
1773 & 0x00FF) | 0x1F00);
1776 if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2)
1777 b43_phy_write(dev, B43_PHY_OFDM(0x7E), 0x78);
1778 if (phy->radio_rev == 8) {
1779 b43_phy_write(dev, B43_PHY_EXTG(0x01),
1780 b43_phy_read(dev, B43_PHY_EXTG(0x01))
1782 b43_phy_write(dev, B43_PHY_OFDM(0x3E),
1783 b43_phy_read(dev, B43_PHY_OFDM(0x3E))
1786 if (has_loopback_gain(phy))
1787 b43_calc_loopback_gain(dev);
1789 if (phy->radio_rev != 8) {
1790 if (phy->initval == 0xFFFF)
1791 phy->initval = b43_radio_init2050(dev);
1793 b43_radio_write16(dev, 0x0078, phy->initval);
1795 if (phy->lo_control->tx_bias == 0xFF) {
1796 b43_lo_g_measure(dev);
1798 if (has_tx_magnification(phy)) {
1799 b43_radio_write16(dev, 0x52,
1800 (b43_radio_read16(dev, 0x52) & 0xFF00)
1801 | phy->lo_control->tx_bias | phy->
1802 lo_control->tx_magn);
1804 b43_radio_write16(dev, 0x52,
1805 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1806 | phy->lo_control->tx_bias);
1808 if (phy->rev >= 6) {
1809 b43_phy_write(dev, B43_PHY_BASE(0x36),
1810 (b43_phy_read(dev, B43_PHY_BASE(0x36))
1811 & 0x0FFF) | (phy->lo_control->
1814 if (dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_PACTRL)
1815 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x8075);
1817 b43_phy_write(dev, B43_PHY_BASE(0x2E), 0x807F);
1819 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x101);
1821 b43_phy_write(dev, B43_PHY_BASE(0x2F), 0x202);
1823 if (phy->gmode || phy->rev >= 2) {
1824 b43_lo_g_adjust(dev);
1825 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
1828 if (!(dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI)) {
1829 /* The specs state to update the NRSSI LT with
1830 * the value 0x7FFFFFFF here. I think that is some weird
1831 * compiler optimization in the original driver.
1832 * Essentially, what we do here is resetting all NRSSI LT
1833 * entries to -32 (see the limit_value() in nrssi_hw_update())
1835 b43_nrssi_hw_update(dev, 0xFFFF); //FIXME?
1836 b43_calc_nrssi_threshold(dev);
1837 } else if (phy->gmode || phy->rev >= 2) {
1838 if (phy->nrssi[0] == -1000) {
1839 B43_WARN_ON(phy->nrssi[1] != -1000);
1840 b43_calc_nrssi_slope(dev);
1842 b43_calc_nrssi_threshold(dev);
1844 if (phy->radio_rev == 8)
1845 b43_phy_write(dev, B43_PHY_EXTG(0x05), 0x3230);
1846 b43_phy_init_pctl(dev);
1847 /* FIXME: The spec says in the following if, the 0 should be replaced
1848 'if OFDM may not be used in the current locale'
1849 but OFDM is legal everywhere */
1850 if ((dev->dev->bus->chip_id == 0x4306
1851 && dev->dev->bus->chip_package == 2) || 0) {
1852 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
1854 b43_phy_write(dev, B43_PHY_OFDM(0xC3),
1855 b43_phy_read(dev, B43_PHY_OFDM(0xC3))
1860 /* Set the baseband attenuation value on chip. */
1861 void b43_phy_set_baseband_attenuation(struct b43_wldev *dev,
1862 u16 baseband_attenuation)
1864 struct b43_phy *phy = &dev->phy;
1866 if (phy->analog == 0) {
1867 b43_write16(dev, B43_MMIO_PHY0, (b43_read16(dev, B43_MMIO_PHY0)
1869 baseband_attenuation);
1870 } else if (phy->analog > 1) {
1871 b43_phy_write(dev, B43_PHY_DACCTL,
1872 (b43_phy_read(dev, B43_PHY_DACCTL)
1873 & 0xFFC3) | (baseband_attenuation << 2));
1875 b43_phy_write(dev, B43_PHY_DACCTL,
1876 (b43_phy_read(dev, B43_PHY_DACCTL)
1877 & 0xFF87) | (baseband_attenuation << 3));
1881 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1882 * This function converts a TSSI value to dBm in Q5.2
1884 static s8 b43_phy_estimate_power_out(struct b43_wldev *dev, s8 tssi)
1886 struct b43_phy *phy = &dev->phy;
1890 tmp = (phy->tgt_idle_tssi - phy->cur_idle_tssi + tssi);
1892 switch (phy->type) {
1895 tmp = limit_value(tmp, 0x00, 0xFF);
1896 dbm = phy->tssi2dbm[tmp];
1897 //TODO: There's a FIXME on the specs
1901 tmp = limit_value(tmp, 0x00, 0x3F);
1902 dbm = phy->tssi2dbm[tmp];
1911 void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
1912 int *_bbatt, int *_rfatt)
1914 int rfatt = *_rfatt;
1915 int bbatt = *_bbatt;
1916 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
1918 /* Get baseband and radio attenuation values into their permitted ranges.
1919 * Radio attenuation affects power level 4 times as much as baseband. */
1921 /* Range constants */
1922 const int rf_min = lo->rfatt_list.min_val;
1923 const int rf_max = lo->rfatt_list.max_val;
1924 const int bb_min = lo->bbatt_list.min_val;
1925 const int bb_max = lo->bbatt_list.max_val;
1928 if (rfatt > rf_max && bbatt > bb_max - 4)
1929 break; /* Can not get it into ranges */
1930 if (rfatt < rf_min && bbatt < bb_min + 4)
1931 break; /* Can not get it into ranges */
1932 if (bbatt > bb_max && rfatt > rf_max - 1)
1933 break; /* Can not get it into ranges */
1934 if (bbatt < bb_min && rfatt < rf_min + 1)
1935 break; /* Can not get it into ranges */
1937 if (bbatt > bb_max) {
1942 if (bbatt < bb_min) {
1947 if (rfatt > rf_max) {
1952 if (rfatt < rf_min) {
1960 *_rfatt = limit_value(rfatt, rf_min, rf_max);
1961 *_bbatt = limit_value(bbatt, bb_min, bb_max);
1964 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1965 void b43_phy_xmitpower(struct b43_wldev *dev)
1967 struct ssb_bus *bus = dev->dev->bus;
1968 struct b43_phy *phy = &dev->phy;
1970 if (phy->cur_idle_tssi == 0)
1972 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1973 (bus->boardinfo.type == SSB_BOARD_BU4306))
1975 #ifdef CONFIG_B43_DEBUG
1976 if (phy->manual_txpower_control)
1980 switch (phy->type) {
1981 case B43_PHYTYPE_A:{
1983 //TODO: Nothing for A PHYs yet :-/
1988 case B43_PHYTYPE_G:{
1993 int desired_pwr, estimated_pwr, pwr_adjust;
1994 int rfatt_delta, bbatt_delta;
1997 unsigned long phylock_flags;
1999 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x0058);
2000 v0 = (s8) (tmp & 0x00FF);
2001 v1 = (s8) ((tmp & 0xFF00) >> 8);
2002 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x005A);
2003 v2 = (s8) (tmp & 0x00FF);
2004 v3 = (s8) ((tmp & 0xFF00) >> 8);
2007 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
2010 b43_shm_read16(dev, B43_SHM_SHARED, 0x0070);
2011 v0 = (s8) (tmp & 0x00FF);
2012 v1 = (s8) ((tmp & 0xFF00) >> 8);
2014 b43_shm_read16(dev, B43_SHM_SHARED, 0x0072);
2015 v2 = (s8) (tmp & 0x00FF);
2016 v3 = (s8) ((tmp & 0xFF00) >> 8);
2017 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
2020 v0 = (v0 + 0x20) & 0x3F;
2021 v1 = (v1 + 0x20) & 0x3F;
2022 v2 = (v2 + 0x20) & 0x3F;
2023 v3 = (v3 + 0x20) & 0x3F;
2026 b43_shm_clear_tssi(dev);
2028 average = (v0 + v1 + v2 + v3 + 2) / 4;
2031 && (b43_shm_read16(dev, B43_SHM_SHARED, 0x005E) &
2036 b43_phy_estimate_power_out(dev, average);
2038 max_pwr = dev->dev->bus->sprom.r1.maxpwr_bg;
2039 if ((dev->dev->bus->sprom.r1.
2040 boardflags_lo & B43_BFL_PACTRL)
2041 && (phy->type == B43_PHYTYPE_G))
2043 if (unlikely(max_pwr <= 0)) {
2045 "Invalid max-TX-power value in SPROM.\n");
2046 max_pwr = 60; /* fake it */
2047 dev->dev->bus->sprom.r1.maxpwr_bg = max_pwr;
2051 max_pwr = min(REG - dev->dev->bus->sprom.antennagain_bgphy - 0x6, max_pwr)
2052 where REG is the max power as per the regulatory domain
2055 /* Get desired power (in Q5.2) */
2056 desired_pwr = INT_TO_Q52(phy->power_level);
2057 /* And limit it. max_pwr already is Q5.2 */
2058 desired_pwr = limit_value(desired_pwr, 0, max_pwr);
2059 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
2061 "Current TX power output: " Q52_FMT
2062 " dBm, " "Desired TX power output: "
2063 Q52_FMT " dBm\n", Q52_ARG(estimated_pwr),
2064 Q52_ARG(desired_pwr));
2067 /* Calculate the adjustment delta. */
2068 pwr_adjust = desired_pwr - estimated_pwr;
2070 /* RF attenuation delta. */
2071 rfatt_delta = ((pwr_adjust + 7) / 8);
2072 /* Lower attenuation => Bigger power output. Negate it. */
2073 rfatt_delta = -rfatt_delta;
2075 /* Baseband attenuation delta. */
2076 bbatt_delta = pwr_adjust / 2;
2077 /* Lower attenuation => Bigger power output. Negate it. */
2078 bbatt_delta = -bbatt_delta;
2079 /* RF att affects power level 4 times as much as
2080 * Baseband attennuation. Subtract it. */
2081 bbatt_delta -= 4 * rfatt_delta;
2083 /* So do we finally need to adjust something? */
2084 if ((rfatt_delta == 0) && (bbatt_delta == 0)) {
2085 b43_lo_g_ctl_mark_cur_used(dev);
2089 /* Calculate the new attenuation values. */
2090 bbatt = phy->bbatt.att;
2091 bbatt += bbatt_delta;
2092 rfatt = phy->rfatt.att;
2093 rfatt += rfatt_delta;
2095 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
2096 tx_control = phy->tx_control;
2097 if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 2)) {
2099 if (tx_control == 0) {
2105 } else if (dev->dev->bus->sprom.r1.
2108 bbatt += 4 * (rfatt - 2);
2111 } else if (rfatt > 4 && tx_control) {
2122 /* Save the control values */
2123 phy->tx_control = tx_control;
2124 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
2125 phy->rfatt.att = rfatt;
2126 phy->bbatt.att = bbatt;
2128 /* Adjust the hardware */
2129 b43_phy_lock(dev, phylock_flags);
2130 b43_radio_lock(dev);
2131 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt,
2133 b43_lo_g_ctl_mark_cur_used(dev);
2134 b43_radio_unlock(dev);
2135 b43_phy_unlock(dev, phylock_flags);
2143 static inline s32 b43_tssi2dbm_ad(s32 num, s32 den)
2148 return (num + den / 2) / den;
2152 s8 b43_tssi2dbm_entry(s8 entry[], u8 index, s16 pab0, s16 pab1, s16 pab2)
2154 s32 m1, m2, f = 256, q, delta;
2157 m1 = b43_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2158 m2 = max(b43_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2162 q = b43_tssi2dbm_ad(f * 4096 -
2163 b43_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2167 } while (delta >= 2);
2168 entry[index] = limit_value(b43_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2172 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2173 int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev)
2175 struct b43_phy *phy = &dev->phy;
2176 s16 pab0, pab1, pab2;
2180 if (phy->type == B43_PHYTYPE_A) {
2181 pab0 = (s16) (dev->dev->bus->sprom.r1.pa1b0);
2182 pab1 = (s16) (dev->dev->bus->sprom.r1.pa1b1);
2183 pab2 = (s16) (dev->dev->bus->sprom.r1.pa1b2);
2185 pab0 = (s16) (dev->dev->bus->sprom.r1.pa0b0);
2186 pab1 = (s16) (dev->dev->bus->sprom.r1.pa0b1);
2187 pab2 = (s16) (dev->dev->bus->sprom.r1.pa0b2);
2190 if ((dev->dev->bus->chip_id == 0x4301) && (phy->radio_ver != 0x2050)) {
2191 phy->tgt_idle_tssi = 0x34;
2192 phy->tssi2dbm = b43_tssi2dbm_b_table;
2196 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2197 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2198 /* The pabX values are set in SPROM. Use them. */
2199 if (phy->type == B43_PHYTYPE_A) {
2200 if ((s8) dev->dev->bus->sprom.r1.itssi_a != 0 &&
2201 (s8) dev->dev->bus->sprom.r1.itssi_a != -1)
2202 phy->tgt_idle_tssi =
2203 (s8) (dev->dev->bus->sprom.r1.itssi_a);
2205 phy->tgt_idle_tssi = 62;
2207 if ((s8) dev->dev->bus->sprom.r1.itssi_bg != 0 &&
2208 (s8) dev->dev->bus->sprom.r1.itssi_bg != -1)
2209 phy->tgt_idle_tssi =
2210 (s8) (dev->dev->bus->sprom.r1.itssi_bg);
2212 phy->tgt_idle_tssi = 62;
2214 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2215 if (dyn_tssi2dbm == NULL) {
2216 b43err(dev->wl, "Could not allocate memory"
2217 "for tssi2dbm table\n");
2220 for (idx = 0; idx < 64; idx++)
2221 if (b43_tssi2dbm_entry
2222 (dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2223 phy->tssi2dbm = NULL;
2224 b43err(dev->wl, "Could not generate "
2225 "tssi2dBm table\n");
2226 kfree(dyn_tssi2dbm);
2229 phy->tssi2dbm = dyn_tssi2dbm;
2230 phy->dyn_tssi_tbl = 1;
2232 /* pabX values not set in SPROM. */
2233 switch (phy->type) {
2235 /* APHY needs a generated table. */
2236 phy->tssi2dbm = NULL;
2237 b43err(dev->wl, "Could not generate tssi2dBm "
2238 "table (wrong SPROM info)!\n");
2241 phy->tgt_idle_tssi = 0x34;
2242 phy->tssi2dbm = b43_tssi2dbm_b_table;
2245 phy->tgt_idle_tssi = 0x34;
2246 phy->tssi2dbm = b43_tssi2dbm_g_table;
2254 int b43_phy_init(struct b43_wldev *dev)
2256 struct b43_phy *phy = &dev->phy;
2259 switch (phy->type) {
2261 if (phy->rev == 2 || phy->rev == 3) {
2269 b43_phy_initb2(dev);
2273 b43_phy_initb4(dev);
2277 b43_phy_initb5(dev);
2281 b43_phy_initb6(dev);
2292 b43err(dev->wl, "Unknown PHYTYPE found\n");
2297 void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2299 struct b43_phy *phy = &dev->phy;
2304 if (antenna == B43_ANTENNA_AUTO0 || antenna == B43_ANTENNA_AUTO1)
2307 hf = b43_hf_read(dev);
2308 hf &= ~B43_HF_ANTDIVHELP;
2309 b43_hf_write(dev, hf);
2311 switch (phy->type) {
2314 tmp = b43_phy_read(dev, B43_PHY_BBANDCFG);
2315 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2316 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2317 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2318 b43_phy_write(dev, B43_PHY_BBANDCFG, tmp);
2321 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2322 if (antenna == B43_ANTENNA_AUTO0)
2323 tmp &= ~B43_PHY_ANTDWELL_AUTODIV1;
2325 tmp |= B43_PHY_ANTDWELL_AUTODIV1;
2326 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2328 if (phy->type == B43_PHYTYPE_G) {
2329 tmp = b43_phy_read(dev, B43_PHY_ANTWRSETT);
2331 tmp |= B43_PHY_ANTWRSETT_ARXDIV;
2333 tmp &= ~B43_PHY_ANTWRSETT_ARXDIV;
2334 b43_phy_write(dev, B43_PHY_ANTWRSETT, tmp);
2335 if (phy->rev >= 2) {
2336 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2337 tmp |= B43_PHY_OFDM61_10;
2338 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2341 b43_phy_read(dev, B43_PHY_DIVSRCHGAINBACK);
2342 tmp = (tmp & 0xFF00) | 0x15;
2343 b43_phy_write(dev, B43_PHY_DIVSRCHGAINBACK,
2346 if (phy->rev == 2) {
2347 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2352 B43_PHY_ADIVRELATED);
2353 tmp = (tmp & 0xFF00) | 8;
2354 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2359 b43_phy_write(dev, B43_PHY_OFDM9B, 0xDC);
2362 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2363 tmp = (tmp & 0xFF00) | 0x24;
2364 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2366 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2368 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2369 if (phy->analog == 3) {
2370 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2372 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2375 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2379 B43_PHY_ADIVRELATED);
2380 tmp = (tmp & 0xFF00) | 8;
2381 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2388 tmp = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
2389 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2390 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2391 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2392 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, tmp);
2398 hf |= B43_HF_ANTDIVHELP;
2399 b43_hf_write(dev, hf);
2402 /* Get the freq, as it has to be written to the device. */
2403 static inline u16 channel2freq_bg(u8 channel)
2405 B43_WARN_ON(!(channel >= 1 && channel <= 14));
2407 return b43_radio_channel_codes_bg[channel - 1];
2410 /* Get the freq, as it has to be written to the device. */
2411 static inline u16 channel2freq_a(u8 channel)
2413 B43_WARN_ON(channel > 200);
2415 return (5000 + 5 * channel);
2418 void b43_radio_lock(struct b43_wldev *dev)
2422 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2423 macctl |= B43_MACCTL_RADIOLOCK;
2424 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2425 /* Commit the write and wait for the device
2426 * to exit any radio register access. */
2427 b43_read32(dev, B43_MMIO_MACCTL);
2431 void b43_radio_unlock(struct b43_wldev *dev)
2435 /* Commit any write */
2436 b43_read16(dev, B43_MMIO_PHY_VER);
2438 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2439 macctl &= ~B43_MACCTL_RADIOLOCK;
2440 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2443 u16 b43_radio_read16(struct b43_wldev *dev, u16 offset)
2445 struct b43_phy *phy = &dev->phy;
2447 switch (phy->type) {
2452 if (phy->radio_ver == 0x2053) {
2455 else if (offset < 0x80)
2457 } else if (phy->radio_ver == 0x2050) {
2467 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2468 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
2471 void b43_radio_write16(struct b43_wldev *dev, u16 offset, u16 val)
2473 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2475 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, val);
2478 static void b43_set_all_gains(struct b43_wldev *dev,
2479 s16 first, s16 second, s16 third)
2481 struct b43_phy *phy = &dev->phy;
2483 u16 start = 0x08, end = 0x18;
2487 if (phy->rev <= 1) {
2492 table = B43_OFDMTAB_GAINX;
2494 table = B43_OFDMTAB_GAINX_R1;
2495 for (i = 0; i < 4; i++)
2496 b43_ofdmtab_write16(dev, table, i, first);
2498 for (i = start; i < end; i++)
2499 b43_ofdmtab_write16(dev, table, i, second);
2502 tmp = ((u16) third << 14) | ((u16) third << 6);
2503 b43_phy_write(dev, 0x04A0,
2504 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | tmp);
2505 b43_phy_write(dev, 0x04A1,
2506 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | tmp);
2507 b43_phy_write(dev, 0x04A2,
2508 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | tmp);
2510 b43_dummy_transmission(dev);
2513 static void b43_set_original_gains(struct b43_wldev *dev)
2515 struct b43_phy *phy = &dev->phy;
2518 u16 start = 0x0008, end = 0x0018;
2520 if (phy->rev <= 1) {
2525 table = B43_OFDMTAB_GAINX;
2527 table = B43_OFDMTAB_GAINX_R1;
2528 for (i = 0; i < 4; i++) {
2530 tmp |= (i & 0x0001) << 1;
2531 tmp |= (i & 0x0002) >> 1;
2533 b43_ofdmtab_write16(dev, table, i, tmp);
2536 for (i = start; i < end; i++)
2537 b43_ofdmtab_write16(dev, table, i, i - start);
2539 b43_phy_write(dev, 0x04A0,
2540 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | 0x4040);
2541 b43_phy_write(dev, 0x04A1,
2542 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | 0x4040);
2543 b43_phy_write(dev, 0x04A2,
2544 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | 0x4000);
2545 b43_dummy_transmission(dev);
2548 /* Synthetic PU workaround */
2549 static void b43_synth_pu_workaround(struct b43_wldev *dev, u8 channel)
2551 struct b43_phy *phy = &dev->phy;
2555 if (phy->radio_ver != 0x2050 || phy->radio_rev >= 6) {
2556 /* We do not need the workaround. */
2560 if (channel <= 10) {
2561 b43_write16(dev, B43_MMIO_CHANNEL,
2562 channel2freq_bg(channel + 4));
2564 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(1));
2567 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
2570 u8 b43_radio_aci_detect(struct b43_wldev *dev, u8 channel)
2572 struct b43_phy *phy = &dev->phy;
2574 u16 saved, rssi, temp;
2577 saved = b43_phy_read(dev, 0x0403);
2578 b43_radio_selectchannel(dev, channel, 0);
2579 b43_phy_write(dev, 0x0403, (saved & 0xFFF8) | 5);
2580 if (phy->aci_hw_rssi)
2581 rssi = b43_phy_read(dev, 0x048A) & 0x3F;
2583 rssi = saved & 0x3F;
2584 /* clamp temp to signed 5bit */
2587 for (i = 0; i < 100; i++) {
2588 temp = (b43_phy_read(dev, 0x047F) >> 8) & 0x3F;
2596 b43_phy_write(dev, 0x0403, saved);
2601 u8 b43_radio_aci_scan(struct b43_wldev * dev)
2603 struct b43_phy *phy = &dev->phy;
2605 unsigned int channel = phy->channel;
2606 unsigned int i, j, start, end;
2607 unsigned long phylock_flags;
2609 if (!((phy->type == B43_PHYTYPE_G) && (phy->rev > 0)))
2612 b43_phy_lock(dev, phylock_flags);
2613 b43_radio_lock(dev);
2614 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2615 b43_phy_write(dev, B43_PHY_G_CRS,
2616 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2617 b43_set_all_gains(dev, 3, 8, 1);
2619 start = (channel - 5 > 0) ? channel - 5 : 1;
2620 end = (channel + 5 < 14) ? channel + 5 : 13;
2622 for (i = start; i <= end; i++) {
2623 if (abs(channel - i) > 2)
2624 ret[i - 1] = b43_radio_aci_detect(dev, i);
2626 b43_radio_selectchannel(dev, channel, 0);
2627 b43_phy_write(dev, 0x0802,
2628 (b43_phy_read(dev, 0x0802) & 0xFFFC) | 0x0003);
2629 b43_phy_write(dev, 0x0403, b43_phy_read(dev, 0x0403) & 0xFFF8);
2630 b43_phy_write(dev, B43_PHY_G_CRS,
2631 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2632 b43_set_original_gains(dev);
2633 for (i = 0; i < 13; i++) {
2636 end = (i + 5 < 13) ? i + 5 : 13;
2637 for (j = i; j < end; j++)
2640 b43_radio_unlock(dev);
2641 b43_phy_unlock(dev, phylock_flags);
2643 return ret[channel - 1];
2646 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2647 void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val)
2649 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2651 b43_phy_write(dev, B43_PHY_NRSSILT_DATA, (u16) val);
2654 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2655 s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset)
2659 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2660 val = b43_phy_read(dev, B43_PHY_NRSSILT_DATA);
2665 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2666 void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val)
2671 for (i = 0; i < 64; i++) {
2672 tmp = b43_nrssi_hw_read(dev, i);
2674 tmp = limit_value(tmp, -32, 31);
2675 b43_nrssi_hw_write(dev, i, tmp);
2679 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2680 void b43_nrssi_mem_update(struct b43_wldev *dev)
2682 struct b43_phy *phy = &dev->phy;
2686 delta = 0x1F - phy->nrssi[0];
2687 for (i = 0; i < 64; i++) {
2688 tmp = (i - delta) * phy->nrssislope;
2691 tmp = limit_value(tmp, 0, 0x3F);
2692 phy->nrssi_lt[i] = tmp;
2696 static void b43_calc_nrssi_offset(struct b43_wldev *dev)
2698 struct b43_phy *phy = &dev->phy;
2699 u16 backup[20] = { 0 };
2704 backup[0] = b43_phy_read(dev, 0x0001);
2705 backup[1] = b43_phy_read(dev, 0x0811);
2706 backup[2] = b43_phy_read(dev, 0x0812);
2707 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2708 backup[3] = b43_phy_read(dev, 0x0814);
2709 backup[4] = b43_phy_read(dev, 0x0815);
2711 backup[5] = b43_phy_read(dev, 0x005A);
2712 backup[6] = b43_phy_read(dev, 0x0059);
2713 backup[7] = b43_phy_read(dev, 0x0058);
2714 backup[8] = b43_phy_read(dev, 0x000A);
2715 backup[9] = b43_phy_read(dev, 0x0003);
2716 backup[10] = b43_radio_read16(dev, 0x007A);
2717 backup[11] = b43_radio_read16(dev, 0x0043);
2719 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) & 0x7FFF);
2720 b43_phy_write(dev, 0x0001,
2721 (b43_phy_read(dev, 0x0001) & 0x3FFF) | 0x4000);
2722 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2723 b43_phy_write(dev, 0x0812,
2724 (b43_phy_read(dev, 0x0812) & 0xFFF3) | 0x0004);
2725 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & ~(0x1 | 0x2));
2726 if (phy->rev >= 6) {
2727 backup[12] = b43_phy_read(dev, 0x002E);
2728 backup[13] = b43_phy_read(dev, 0x002F);
2729 backup[14] = b43_phy_read(dev, 0x080F);
2730 backup[15] = b43_phy_read(dev, 0x0810);
2731 backup[16] = b43_phy_read(dev, 0x0801);
2732 backup[17] = b43_phy_read(dev, 0x0060);
2733 backup[18] = b43_phy_read(dev, 0x0014);
2734 backup[19] = b43_phy_read(dev, 0x0478);
2736 b43_phy_write(dev, 0x002E, 0);
2737 b43_phy_write(dev, 0x002F, 0);
2738 b43_phy_write(dev, 0x080F, 0);
2739 b43_phy_write(dev, 0x0810, 0);
2740 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478) | 0x0100);
2741 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801) | 0x0040);
2742 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) | 0x0040);
2743 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014) | 0x0200);
2745 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0070);
2746 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0080);
2749 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2753 for (i = 7; i >= 4; i--) {
2754 b43_radio_write16(dev, 0x007B, i);
2757 (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2760 if (v47F < 31 && saved == 0xFFFF)
2763 if (saved == 0xFFFF)
2766 b43_radio_write16(dev, 0x007A,
2767 b43_radio_read16(dev, 0x007A) & 0x007F);
2768 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2769 b43_phy_write(dev, 0x0814,
2770 b43_phy_read(dev, 0x0814) | 0x0001);
2771 b43_phy_write(dev, 0x0815,
2772 b43_phy_read(dev, 0x0815) & 0xFFFE);
2774 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2775 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x000C);
2776 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x0030);
2777 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x0030);
2778 b43_phy_write(dev, 0x005A, 0x0480);
2779 b43_phy_write(dev, 0x0059, 0x0810);
2780 b43_phy_write(dev, 0x0058, 0x000D);
2781 if (phy->rev == 0) {
2782 b43_phy_write(dev, 0x0003, 0x0122);
2784 b43_phy_write(dev, 0x000A, b43_phy_read(dev, 0x000A)
2787 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2788 b43_phy_write(dev, 0x0814,
2789 b43_phy_read(dev, 0x0814) | 0x0004);
2790 b43_phy_write(dev, 0x0815,
2791 b43_phy_read(dev, 0x0815) & 0xFFFB);
2793 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003) & 0xFF9F)
2795 b43_radio_write16(dev, 0x007A,
2796 b43_radio_read16(dev, 0x007A) | 0x000F);
2797 b43_set_all_gains(dev, 3, 0, 1);
2798 b43_radio_write16(dev, 0x0043, (b43_radio_read16(dev, 0x0043)
2799 & 0x00F0) | 0x000F);
2801 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2805 for (i = 0; i < 4; i++) {
2806 b43_radio_write16(dev, 0x007B, i);
2809 (s16) ((b43_phy_read(dev, 0x047F) >> 8) &
2813 if (v47F > -31 && saved == 0xFFFF)
2816 if (saved == 0xFFFF)
2821 b43_radio_write16(dev, 0x007B, saved);
2823 if (phy->rev >= 6) {
2824 b43_phy_write(dev, 0x002E, backup[12]);
2825 b43_phy_write(dev, 0x002F, backup[13]);
2826 b43_phy_write(dev, 0x080F, backup[14]);
2827 b43_phy_write(dev, 0x0810, backup[15]);
2829 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2830 b43_phy_write(dev, 0x0814, backup[3]);
2831 b43_phy_write(dev, 0x0815, backup[4]);
2833 b43_phy_write(dev, 0x005A, backup[5]);
2834 b43_phy_write(dev, 0x0059, backup[6]);
2835 b43_phy_write(dev, 0x0058, backup[7]);
2836 b43_phy_write(dev, 0x000A, backup[8]);
2837 b43_phy_write(dev, 0x0003, backup[9]);
2838 b43_radio_write16(dev, 0x0043, backup[11]);
2839 b43_radio_write16(dev, 0x007A, backup[10]);
2840 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x1 | 0x2);
2841 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) | 0x8000);
2842 b43_set_original_gains(dev);
2843 if (phy->rev >= 6) {
2844 b43_phy_write(dev, 0x0801, backup[16]);
2845 b43_phy_write(dev, 0x0060, backup[17]);
2846 b43_phy_write(dev, 0x0014, backup[18]);
2847 b43_phy_write(dev, 0x0478, backup[19]);
2849 b43_phy_write(dev, 0x0001, backup[0]);
2850 b43_phy_write(dev, 0x0812, backup[2]);
2851 b43_phy_write(dev, 0x0811, backup[1]);
2854 void b43_calc_nrssi_slope(struct b43_wldev *dev)
2856 struct b43_phy *phy = &dev->phy;
2857 u16 backup[18] = { 0 };
2861 switch (phy->type) {
2863 backup[0] = b43_radio_read16(dev, 0x007A);
2864 backup[1] = b43_radio_read16(dev, 0x0052);
2865 backup[2] = b43_radio_read16(dev, 0x0043);
2866 backup[3] = b43_phy_read(dev, 0x0030);
2867 backup[4] = b43_phy_read(dev, 0x0026);
2868 backup[5] = b43_phy_read(dev, 0x0015);
2869 backup[6] = b43_phy_read(dev, 0x002A);
2870 backup[7] = b43_phy_read(dev, 0x0020);
2871 backup[8] = b43_phy_read(dev, 0x005A);
2872 backup[9] = b43_phy_read(dev, 0x0059);
2873 backup[10] = b43_phy_read(dev, 0x0058);
2874 backup[11] = b43_read16(dev, 0x03E2);
2875 backup[12] = b43_read16(dev, 0x03E6);
2876 backup[13] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2878 tmp = b43_radio_read16(dev, 0x007A);
2879 tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
2880 b43_radio_write16(dev, 0x007A, tmp);
2881 b43_phy_write(dev, 0x0030, 0x00FF);
2882 b43_write16(dev, 0x03EC, 0x7F7F);
2883 b43_phy_write(dev, 0x0026, 0x0000);
2884 b43_phy_write(dev, 0x0015, b43_phy_read(dev, 0x0015) | 0x0020);
2885 b43_phy_write(dev, 0x002A, 0x08A3);
2886 b43_radio_write16(dev, 0x007A,
2887 b43_radio_read16(dev, 0x007A) | 0x0080);
2889 nrssi0 = (s16) b43_phy_read(dev, 0x0027);
2890 b43_radio_write16(dev, 0x007A,
2891 b43_radio_read16(dev, 0x007A) & 0x007F);
2892 if (phy->rev >= 2) {
2893 b43_write16(dev, 0x03E6, 0x0040);
2894 } else if (phy->rev == 0) {
2895 b43_write16(dev, 0x03E6, 0x0122);
2897 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2899 B43_MMIO_CHANNEL_EXT) & 0x2000);
2901 b43_phy_write(dev, 0x0020, 0x3F3F);
2902 b43_phy_write(dev, 0x0015, 0xF330);
2903 b43_radio_write16(dev, 0x005A, 0x0060);
2904 b43_radio_write16(dev, 0x0043,
2905 b43_radio_read16(dev, 0x0043) & 0x00F0);
2906 b43_phy_write(dev, 0x005A, 0x0480);
2907 b43_phy_write(dev, 0x0059, 0x0810);
2908 b43_phy_write(dev, 0x0058, 0x000D);
2911 nrssi1 = (s16) b43_phy_read(dev, 0x0027);
2912 b43_phy_write(dev, 0x0030, backup[3]);
2913 b43_radio_write16(dev, 0x007A, backup[0]);
2914 b43_write16(dev, 0x03E2, backup[11]);
2915 b43_phy_write(dev, 0x0026, backup[4]);
2916 b43_phy_write(dev, 0x0015, backup[5]);
2917 b43_phy_write(dev, 0x002A, backup[6]);
2918 b43_synth_pu_workaround(dev, phy->channel);
2920 b43_write16(dev, 0x03F4, backup[13]);
2922 b43_phy_write(dev, 0x0020, backup[7]);
2923 b43_phy_write(dev, 0x005A, backup[8]);
2924 b43_phy_write(dev, 0x0059, backup[9]);
2925 b43_phy_write(dev, 0x0058, backup[10]);
2926 b43_radio_write16(dev, 0x0052, backup[1]);
2927 b43_radio_write16(dev, 0x0043, backup[2]);
2929 if (nrssi0 == nrssi1)
2930 phy->nrssislope = 0x00010000;
2932 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2935 phy->nrssi[0] = nrssi0;
2936 phy->nrssi[1] = nrssi1;
2940 if (phy->radio_rev >= 9)
2942 if (phy->radio_rev == 8)
2943 b43_calc_nrssi_offset(dev);
2945 b43_phy_write(dev, B43_PHY_G_CRS,
2946 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2947 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2948 backup[7] = b43_read16(dev, 0x03E2);
2949 b43_write16(dev, 0x03E2, b43_read16(dev, 0x03E2) | 0x8000);
2950 backup[0] = b43_radio_read16(dev, 0x007A);
2951 backup[1] = b43_radio_read16(dev, 0x0052);
2952 backup[2] = b43_radio_read16(dev, 0x0043);
2953 backup[3] = b43_phy_read(dev, 0x0015);
2954 backup[4] = b43_phy_read(dev, 0x005A);
2955 backup[5] = b43_phy_read(dev, 0x0059);
2956 backup[6] = b43_phy_read(dev, 0x0058);
2957 backup[8] = b43_read16(dev, 0x03E6);
2958 backup[9] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2959 if (phy->rev >= 3) {
2960 backup[10] = b43_phy_read(dev, 0x002E);
2961 backup[11] = b43_phy_read(dev, 0x002F);
2962 backup[12] = b43_phy_read(dev, 0x080F);
2963 backup[13] = b43_phy_read(dev, B43_PHY_G_LO_CONTROL);
2964 backup[14] = b43_phy_read(dev, 0x0801);
2965 backup[15] = b43_phy_read(dev, 0x0060);
2966 backup[16] = b43_phy_read(dev, 0x0014);
2967 backup[17] = b43_phy_read(dev, 0x0478);
2968 b43_phy_write(dev, 0x002E, 0);
2969 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, 0);
2974 b43_phy_write(dev, 0x0478,
2975 b43_phy_read(dev, 0x0478)
2977 b43_phy_write(dev, 0x0801,
2978 b43_phy_read(dev, 0x0801)
2983 b43_phy_write(dev, 0x0801,
2984 b43_phy_read(dev, 0x0801)
2988 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060)
2990 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014)
2993 b43_radio_write16(dev, 0x007A,
2994 b43_radio_read16(dev, 0x007A) | 0x0070);
2995 b43_set_all_gains(dev, 0, 8, 0);
2996 b43_radio_write16(dev, 0x007A,
2997 b43_radio_read16(dev, 0x007A) & 0x00F7);
2998 if (phy->rev >= 2) {
2999 b43_phy_write(dev, 0x0811,
3000 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
3002 b43_phy_write(dev, 0x0812,
3003 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
3006 b43_radio_write16(dev, 0x007A,
3007 b43_radio_read16(dev, 0x007A) | 0x0080);
3010 nrssi0 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
3011 if (nrssi0 >= 0x0020)
3014 b43_radio_write16(dev, 0x007A,
3015 b43_radio_read16(dev, 0x007A) & 0x007F);
3016 if (phy->rev >= 2) {
3017 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003)
3018 & 0xFF9F) | 0x0040);
3021 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3022 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3024 b43_radio_write16(dev, 0x007A,
3025 b43_radio_read16(dev, 0x007A) | 0x000F);
3026 b43_phy_write(dev, 0x0015, 0xF330);
3027 if (phy->rev >= 2) {
3028 b43_phy_write(dev, 0x0812,
3029 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
3031 b43_phy_write(dev, 0x0811,
3032 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
3036 b43_set_all_gains(dev, 3, 0, 1);
3037 if (phy->radio_rev == 8) {
3038 b43_radio_write16(dev, 0x0043, 0x001F);
3040 tmp = b43_radio_read16(dev, 0x0052) & 0xFF0F;
3041 b43_radio_write16(dev, 0x0052, tmp | 0x0060);
3042 tmp = b43_radio_read16(dev, 0x0043) & 0xFFF0;
3043 b43_radio_write16(dev, 0x0043, tmp | 0x0009);
3045 b43_phy_write(dev, 0x005A, 0x0480);
3046 b43_phy_write(dev, 0x0059, 0x0810);
3047 b43_phy_write(dev, 0x0058, 0x000D);
3049 nrssi1 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
3050 if (nrssi1 >= 0x0020)
3052 if (nrssi0 == nrssi1)
3053 phy->nrssislope = 0x00010000;
3055 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
3057 phy->nrssi[0] = nrssi1;
3058 phy->nrssi[1] = nrssi0;
3060 if (phy->rev >= 3) {
3061 b43_phy_write(dev, 0x002E, backup[10]);
3062 b43_phy_write(dev, 0x002F, backup[11]);
3063 b43_phy_write(dev, 0x080F, backup[12]);
3064 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, backup[13]);
3066 if (phy->rev >= 2) {
3067 b43_phy_write(dev, 0x0812,
3068 b43_phy_read(dev, 0x0812) & 0xFFCF);
3069 b43_phy_write(dev, 0x0811,
3070 b43_phy_read(dev, 0x0811) & 0xFFCF);
3073 b43_radio_write16(dev, 0x007A, backup[0]);
3074 b43_radio_write16(dev, 0x0052, backup[1]);
3075 b43_radio_write16(dev, 0x0043, backup[2]);
3076 b43_write16(dev, 0x03E2, backup[7]);
3077 b43_write16(dev, 0x03E6, backup[8]);
3078 b43_write16(dev, B43_MMIO_CHANNEL_EXT, backup[9]);
3079 b43_phy_write(dev, 0x0015, backup[3]);
3080 b43_phy_write(dev, 0x005A, backup[4]);
3081 b43_phy_write(dev, 0x0059, backup[5]);
3082 b43_phy_write(dev, 0x0058, backup[6]);
3083 b43_synth_pu_workaround(dev, phy->channel);
3084 b43_phy_write(dev, 0x0802,
3085 b43_phy_read(dev, 0x0802) | (0x0001 | 0x0002));
3086 b43_set_original_gains(dev);
3087 b43_phy_write(dev, B43_PHY_G_CRS,
3088 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
3089 if (phy->rev >= 3) {
3090 b43_phy_write(dev, 0x0801, backup[14]);
3091 b43_phy_write(dev, 0x0060, backup[15]);
3092 b43_phy_write(dev, 0x0014, backup[16]);
3093 b43_phy_write(dev, 0x0478, backup[17]);
3095 b43_nrssi_mem_update(dev);
3096 b43_calc_nrssi_threshold(dev);
3103 void b43_calc_nrssi_threshold(struct b43_wldev *dev)
3105 struct b43_phy *phy = &dev->phy;
3111 switch (phy->type) {
3112 case B43_PHYTYPE_B:{
3113 if (phy->radio_ver != 0x2050)
3116 (dev->dev->bus->sprom.r1.
3117 boardflags_lo & B43_BFL_RSSI))
3120 if (phy->radio_rev >= 6) {
3122 (phy->nrssi[1] - phy->nrssi[0]) * 32;
3123 threshold += 20 * (phy->nrssi[0] + 1);
3126 threshold = phy->nrssi[1] - 5;
3128 threshold = limit_value(threshold, 0, 0x3E);
3129 b43_phy_read(dev, 0x0020); /* dummy read */
3130 b43_phy_write(dev, 0x0020,
3131 (((u16) threshold) << 8) | 0x001C);
3133 if (phy->radio_rev >= 6) {
3134 b43_phy_write(dev, 0x0087, 0x0E0D);
3135 b43_phy_write(dev, 0x0086, 0x0C0B);
3136 b43_phy_write(dev, 0x0085, 0x0A09);
3137 b43_phy_write(dev, 0x0084, 0x0808);
3138 b43_phy_write(dev, 0x0083, 0x0808);
3139 b43_phy_write(dev, 0x0082, 0x0604);
3140 b43_phy_write(dev, 0x0081, 0x0302);
3141 b43_phy_write(dev, 0x0080, 0x0100);
3147 !(dev->dev->bus->sprom.r1.boardflags_lo & B43_BFL_RSSI)) {
3148 tmp16 = b43_nrssi_hw_read(dev, 0x20);
3152 b43_phy_write(dev, 0x048A,
3153 (b43_phy_read(dev, 0x048A)
3154 & 0xF000) | 0x09EB);
3156 b43_phy_write(dev, 0x048A,
3157 (b43_phy_read(dev, 0x048A)
3158 & 0xF000) | 0x0AED);
3161 if (phy->interfmode == B43_INTERFMODE_NONWLAN) {
3164 } else if (!phy->aci_wlan_automatic && phy->aci_enable) {
3172 a = a * (phy->nrssi[1] - phy->nrssi[0]);
3173 a += (phy->nrssi[0] << 6);
3179 a = limit_value(a, -31, 31);
3181 b = b * (phy->nrssi[1] - phy->nrssi[0]);
3182 b += (phy->nrssi[0] << 6);
3188 b = limit_value(b, -31, 31);
3190 tmp_u16 = b43_phy_read(dev, 0x048A) & 0xF000;
3191 tmp_u16 |= ((u32) b & 0x0000003F);
3192 tmp_u16 |= (((u32) a & 0x0000003F) << 6);
3193 b43_phy_write(dev, 0x048A, tmp_u16);
3201 /* Stack implementation to save/restore values from the
3202 * interference mitigation code.
3203 * It is save to restore values in random order.
3205 static void _stack_save(u32 * _stackptr, size_t * stackidx,
3206 u8 id, u16 offset, u16 value)
3208 u32 *stackptr = &(_stackptr[*stackidx]);
3210 B43_WARN_ON(offset & 0xF000);
3211 B43_WARN_ON(id & 0xF0);
3213 *stackptr |= ((u32) id) << 12;
3214 *stackptr |= ((u32) value) << 16;
3216 B43_WARN_ON(*stackidx >= B43_INTERFSTACK_SIZE);
3219 static u16 _stack_restore(u32 * stackptr, u8 id, u16 offset)
3223 B43_WARN_ON(offset & 0xF000);
3224 B43_WARN_ON(id & 0xF0);
3225 for (i = 0; i < B43_INTERFSTACK_SIZE; i++, stackptr++) {
3226 if ((*stackptr & 0x00000FFF) != offset)
3228 if (((*stackptr & 0x0000F000) >> 12) != id)
3230 return ((*stackptr & 0xFFFF0000) >> 16);
3237 #define phy_stacksave(offset) \
3239 _stack_save(stack, &stackidx, 0x1, (offset), \
3240 b43_phy_read(dev, (offset))); \
3242 #define phy_stackrestore(offset) \
3244 b43_phy_write(dev, (offset), \
3245 _stack_restore(stack, 0x1, \
3248 #define radio_stacksave(offset) \
3250 _stack_save(stack, &stackidx, 0x2, (offset), \
3251 b43_radio_read16(dev, (offset))); \
3253 #define radio_stackrestore(offset) \
3255 b43_radio_write16(dev, (offset), \
3256 _stack_restore(stack, 0x2, \
3259 #define ofdmtab_stacksave(table, offset) \
3261 _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
3262 b43_ofdmtab_read16(dev, (table), (offset))); \
3264 #define ofdmtab_stackrestore(table, offset) \
3266 b43_ofdmtab_write16(dev, (table), (offset), \
3267 _stack_restore(stack, 0x3, \
3268 (offset)|(table))); \
3272 b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
3274 struct b43_phy *phy = &dev->phy;
3276 size_t stackidx = 0;
3277 u32 *stack = phy->interfstack;
3280 case B43_INTERFMODE_NONWLAN:
3281 if (phy->rev != 1) {
3282 b43_phy_write(dev, 0x042B,
3283 b43_phy_read(dev, 0x042B) | 0x0800);
3284 b43_phy_write(dev, B43_PHY_G_CRS,
3286 B43_PHY_G_CRS) & ~0x4000);
3289 radio_stacksave(0x0078);
3290 tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
3291 flipped = flip_4bit(tmp);
3292 if (flipped < 10 && flipped >= 8)
3294 else if (flipped >= 10)
3296 flipped = flip_4bit(flipped);
3297 flipped = (flipped << 1) | 0x0020;
3298 b43_radio_write16(dev, 0x0078, flipped);
3300 b43_calc_nrssi_threshold(dev);
3302 phy_stacksave(0x0406);
3303 b43_phy_write(dev, 0x0406, 0x7E28);
3305 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x0800);
3306 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3308 B43_PHY_RADIO_BITFIELD) | 0x1000);
3310 phy_stacksave(0x04A0);
3311 b43_phy_write(dev, 0x04A0,
3312 (b43_phy_read(dev, 0x04A0) & 0xC0C0) | 0x0008);
3313 phy_stacksave(0x04A1);
3314 b43_phy_write(dev, 0x04A1,
3315 (b43_phy_read(dev, 0x04A1) & 0xC0C0) | 0x0605);
3316 phy_stacksave(0x04A2);
3317 b43_phy_write(dev, 0x04A2,
3318 (b43_phy_read(dev, 0x04A2) & 0xC0C0) | 0x0204);
3319 phy_stacksave(0x04A8);
3320 b43_phy_write(dev, 0x04A8,
3321 (b43_phy_read(dev, 0x04A8) & 0xC0C0) | 0x0803);
3322 phy_stacksave(0x04AB);
3323 b43_phy_write(dev, 0x04AB,
3324 (b43_phy_read(dev, 0x04AB) & 0xC0C0) | 0x0605);
3326 phy_stacksave(0x04A7);
3327 b43_phy_write(dev, 0x04A7, 0x0002);
3328 phy_stacksave(0x04A3);
3329 b43_phy_write(dev, 0x04A3, 0x287A);
3330 phy_stacksave(0x04A9);
3331 b43_phy_write(dev, 0x04A9, 0x2027);
3332 phy_stacksave(0x0493);
3333 b43_phy_write(dev, 0x0493, 0x32F5);
3334 phy_stacksave(0x04AA);
3335 b43_phy_write(dev, 0x04AA, 0x2027);
3336 phy_stacksave(0x04AC);
3337 b43_phy_write(dev, 0x04AC, 0x32F5);
3339 case B43_INTERFMODE_MANUALWLAN:
3340 if (b43_phy_read(dev, 0x0033) & 0x0800)
3343 phy->aci_enable = 1;
3345 phy_stacksave(B43_PHY_RADIO_BITFIELD);
3346 phy_stacksave(B43_PHY_G_CRS);
3348 phy_stacksave(0x0406);
3350 phy_stacksave(0x04C0);
3351 phy_stacksave(0x04C1);
3353 phy_stacksave(0x0033);
3354 phy_stacksave(0x04A7);
3355 phy_stacksave(0x04A3);
3356 phy_stacksave(0x04A9);
3357 phy_stacksave(0x04AA);
3358 phy_stacksave(0x04AC);
3359 phy_stacksave(0x0493);
3360 phy_stacksave(0x04A1);
3361 phy_stacksave(0x04A0);
3362 phy_stacksave(0x04A2);
3363 phy_stacksave(0x048A);
3364 phy_stacksave(0x04A8);
3365 phy_stacksave(0x04AB);
3366 if (phy->rev == 2) {
3367 phy_stacksave(0x04AD);
3368 phy_stacksave(0x04AE);
3369 } else if (phy->rev >= 3) {
3370 phy_stacksave(0x04AD);
3371 phy_stacksave(0x0415);
3372 phy_stacksave(0x0416);
3373 phy_stacksave(0x0417);
3374 ofdmtab_stacksave(0x1A00, 0x2);
3375 ofdmtab_stacksave(0x1A00, 0x3);
3377 phy_stacksave(0x042B);
3378 phy_stacksave(0x048C);
3380 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3381 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3383 b43_phy_write(dev, B43_PHY_G_CRS,
3384 (b43_phy_read(dev, B43_PHY_G_CRS)
3385 & 0xFFFC) | 0x0002);
3387 b43_phy_write(dev, 0x0033, 0x0800);
3388 b43_phy_write(dev, 0x04A3, 0x2027);
3389 b43_phy_write(dev, 0x04A9, 0x1CA8);
3390 b43_phy_write(dev, 0x0493, 0x287A);
3391 b43_phy_write(dev, 0x04AA, 0x1CA8);
3392 b43_phy_write(dev, 0x04AC, 0x287A);
3394 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3395 & 0xFFC0) | 0x001A);
3396 b43_phy_write(dev, 0x04A7, 0x000D);
3399 b43_phy_write(dev, 0x0406, 0xFF0D);
3400 } else if (phy->rev == 2) {
3401 b43_phy_write(dev, 0x04C0, 0xFFFF);
3402 b43_phy_write(dev, 0x04C1, 0x00A9);
3404 b43_phy_write(dev, 0x04C0, 0x00C1);
3405 b43_phy_write(dev, 0x04C1, 0x0059);
3408 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3409 & 0xC0FF) | 0x1800);
3410 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3411 & 0xFFC0) | 0x0015);
3412 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3413 & 0xCFFF) | 0x1000);
3414 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3415 & 0xF0FF) | 0x0A00);
3416 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3417 & 0xCFFF) | 0x1000);
3418 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3419 & 0xF0FF) | 0x0800);
3420 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3421 & 0xFFCF) | 0x0010);
3422 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3423 & 0xFFF0) | 0x0005);
3424 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3425 & 0xFFCF) | 0x0010);
3426 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3427 & 0xFFF0) | 0x0006);
3428 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3429 & 0xF0FF) | 0x0800);
3430 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3431 & 0xF0FF) | 0x0500);
3432 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3433 & 0xFFF0) | 0x000B);
3435 if (phy->rev >= 3) {
3436 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3438 b43_phy_write(dev, 0x0415, (b43_phy_read(dev, 0x0415)
3439 & 0x8000) | 0x36D8);
3440 b43_phy_write(dev, 0x0416, (b43_phy_read(dev, 0x0416)
3441 & 0x8000) | 0x36D8);
3442 b43_phy_write(dev, 0x0417, (b43_phy_read(dev, 0x0417)
3443 & 0xFE00) | 0x016D);
3445 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3447 b43_phy_write(dev, 0x048A, (b43_phy_read(dev, 0x048A)
3448 & 0x9FFF) | 0x2000);
3449 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ACIW);
3451 if (phy->rev >= 2) {
3452 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B)
3455 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
3456 & 0xF0FF) | 0x0200);
3457 if (phy->rev == 2) {
3458 b43_phy_write(dev, 0x04AE, (b43_phy_read(dev, 0x04AE)
3459 & 0xFF00) | 0x007F);
3460 b43_phy_write(dev, 0x04AD, (b43_phy_read(dev, 0x04AD)
3461 & 0x00FF) | 0x1300);
3462 } else if (phy->rev >= 6) {
3463 b43_ofdmtab_write16(dev, 0x1A00, 0x3, 0x007F);
3464 b43_ofdmtab_write16(dev, 0x1A00, 0x2, 0x007F);
3465 b43_phy_write(dev, 0x04AD, b43_phy_read(dev, 0x04AD)
3468 b43_calc_nrssi_slope(dev);
3476 b43_radio_interference_mitigation_disable(struct b43_wldev *dev, int mode)
3478 struct b43_phy *phy = &dev->phy;
3479 u32 *stack = phy->interfstack;
3482 case B43_INTERFMODE_NONWLAN:
3483 if (phy->rev != 1) {
3484 b43_phy_write(dev, 0x042B,
3485 b43_phy_read(dev, 0x042B) & ~0x0800);
3486 b43_phy_write(dev, B43_PHY_G_CRS,
3488 B43_PHY_G_CRS) | 0x4000);
3491 radio_stackrestore(0x0078);
3492 b43_calc_nrssi_threshold(dev);
3493 phy_stackrestore(0x0406);
3494 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) & ~0x0800);
3495 if (!dev->bad_frames_preempt) {
3496 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3497 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3500 b43_phy_write(dev, B43_PHY_G_CRS,
3501 b43_phy_read(dev, B43_PHY_G_CRS) | 0x4000);
3502 phy_stackrestore(0x04A0);
3503 phy_stackrestore(0x04A1);
3504 phy_stackrestore(0x04A2);
3505 phy_stackrestore(0x04A8);
3506 phy_stackrestore(0x04AB);
3507 phy_stackrestore(0x04A7);
3508 phy_stackrestore(0x04A3);
3509 phy_stackrestore(0x04A9);
3510 phy_stackrestore(0x0493);
3511 phy_stackrestore(0x04AA);
3512 phy_stackrestore(0x04AC);
3514 case B43_INTERFMODE_MANUALWLAN:
3515 if (!(b43_phy_read(dev, 0x0033) & 0x0800))
3518 phy->aci_enable = 0;
3520 phy_stackrestore(B43_PHY_RADIO_BITFIELD);
3521 phy_stackrestore(B43_PHY_G_CRS);
3522 phy_stackrestore(0x0033);
3523 phy_stackrestore(0x04A3);
3524 phy_stackrestore(0x04A9);
3525 phy_stackrestore(0x0493);
3526 phy_stackrestore(0x04AA);
3527 phy_stackrestore(0x04AC);
3528 phy_stackrestore(0x04A0);
3529 phy_stackrestore(0x04A7);
3530 if (phy->rev >= 2) {
3531 phy_stackrestore(0x04C0);
3532 phy_stackrestore(0x04C1);
3534 phy_stackrestore(0x0406);
3535 phy_stackrestore(0x04A1);
3536 phy_stackrestore(0x04AB);
3537 phy_stackrestore(0x04A8);
3538 if (phy->rev == 2) {
3539 phy_stackrestore(0x04AD);
3540 phy_stackrestore(0x04AE);
3541 } else if (phy->rev >= 3) {
3542 phy_stackrestore(0x04AD);
3543 phy_stackrestore(0x0415);
3544 phy_stackrestore(0x0416);
3545 phy_stackrestore(0x0417);
3546 ofdmtab_stackrestore(0x1A00, 0x2);
3547 ofdmtab_stackrestore(0x1A00, 0x3);
3549 phy_stackrestore(0x04A2);
3550 phy_stackrestore(0x048A);
3551 phy_stackrestore(0x042B);
3552 phy_stackrestore(0x048C);
3553 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ACIW);
3554 b43_calc_nrssi_slope(dev);
3561 #undef phy_stacksave
3562 #undef phy_stackrestore
3563 #undef radio_stacksave
3564 #undef radio_stackrestore
3565 #undef ofdmtab_stacksave
3566 #undef ofdmtab_stackrestore
3568 int b43_radio_set_interference_mitigation(struct b43_wldev *dev, int mode)
3570 struct b43_phy *phy = &dev->phy;
3573 if ((phy->type != B43_PHYTYPE_G) || (phy->rev == 0) || (!phy->gmode))
3576 phy->aci_wlan_automatic = 0;
3578 case B43_INTERFMODE_AUTOWLAN:
3579 phy->aci_wlan_automatic = 1;
3580 if (phy->aci_enable)
3581 mode = B43_INTERFMODE_MANUALWLAN;
3583 mode = B43_INTERFMODE_NONE;
3585 case B43_INTERFMODE_NONE:
3586 case B43_INTERFMODE_NONWLAN:
3587 case B43_INTERFMODE_MANUALWLAN:
3593 currentmode = phy->interfmode;
3594 if (currentmode == mode)
3596 if (currentmode != B43_INTERFMODE_NONE)
3597 b43_radio_interference_mitigation_disable(dev, currentmode);
3599 if (mode == B43_INTERFMODE_NONE) {
3600 phy->aci_enable = 0;
3601 phy->aci_hw_rssi = 0;
3603 b43_radio_interference_mitigation_enable(dev, mode);
3604 phy->interfmode = mode;
3609 static u16 b43_radio_core_calibration_value(struct b43_wldev *dev)
3611 u16 reg, index, ret;
3613 static const u8 rcc_table[] = {
3614 0x02, 0x03, 0x01, 0x0F,
3615 0x06, 0x07, 0x05, 0x0F,
3616 0x0A, 0x0B, 0x09, 0x0F,
3617 0x0E, 0x0F, 0x0D, 0x0F,
3620 reg = b43_radio_read16(dev, 0x60);
3621 index = (reg & 0x001E) >> 1;
3622 ret = rcc_table[index] << 1;
3623 ret |= (reg & 0x0001);
3629 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
3630 static u16 radio2050_rfover_val(struct b43_wldev *dev,
3631 u16 phy_register, unsigned int lpd)
3633 struct b43_phy *phy = &dev->phy;
3634 struct ssb_sprom *sprom = &(dev->dev->bus->sprom);
3639 if (has_loopback_gain(phy)) {
3640 int max_lb_gain = phy->max_lb_gain;
3644 if (phy->radio_rev == 8)
3645 max_lb_gain += 0x3E;
3647 max_lb_gain += 0x26;
3648 if (max_lb_gain >= 0x46) {
3650 max_lb_gain -= 0x46;
3651 } else if (max_lb_gain >= 0x3A) {
3653 max_lb_gain -= 0x3A;
3654 } else if (max_lb_gain >= 0x2E) {
3656 max_lb_gain -= 0x2E;
3659 max_lb_gain -= 0x10;
3662 for (i = 0; i < 16; i++) {
3663 max_lb_gain -= (i * 6);
3664 if (max_lb_gain < 6)
3668 if ((phy->rev < 7) ||
3669 !(sprom->r1.boardflags_lo & B43_BFL_EXTLNA)) {
3670 if (phy_register == B43_PHY_RFOVER) {
3672 } else if (phy_register == B43_PHY_RFOVERVAL) {
3679 return (0x0092 | extlna);
3681 return (0x0093 | extlna);
3687 if (phy_register == B43_PHY_RFOVER) {
3689 } else if (phy_register == B43_PHY_RFOVERVAL) {
3697 return (0x8092 | extlna);
3699 return (0x2092 | extlna);
3701 return (0x2093 | extlna);
3708 if ((phy->rev < 7) ||
3709 !(sprom->r1.boardflags_lo & B43_BFL_EXTLNA)) {
3710 if (phy_register == B43_PHY_RFOVER) {
3712 } else if (phy_register == B43_PHY_RFOVERVAL) {
3727 if (phy_register == B43_PHY_RFOVER) {
3729 } else if (phy_register == B43_PHY_RFOVERVAL) {
3748 struct init2050_saved_values {
3749 /* Core registers */
3753 /* Radio registers */
3766 u16 phy_analogoverval;
3774 u16 b43_radio_init2050(struct b43_wldev *dev)
3776 struct b43_phy *phy = &dev->phy;
3777 struct init2050_saved_values sav;
3782 u32 tmp1 = 0, tmp2 = 0;
3784 memset(&sav, 0, sizeof(sav)); /* get rid of "may be used uninitialized..." */
3786 sav.radio_43 = b43_radio_read16(dev, 0x43);
3787 sav.radio_51 = b43_radio_read16(dev, 0x51);
3788 sav.radio_52 = b43_radio_read16(dev, 0x52);
3789 sav.phy_pgactl = b43_phy_read(dev, B43_PHY_PGACTL);
3790 sav.phy_base_5A = b43_phy_read(dev, B43_PHY_BASE(0x5A));
3791 sav.phy_base_59 = b43_phy_read(dev, B43_PHY_BASE(0x59));
3792 sav.phy_base_58 = b43_phy_read(dev, B43_PHY_BASE(0x58));
3794 if (phy->type == B43_PHYTYPE_B) {
3795 sav.phy_base_30 = b43_phy_read(dev, B43_PHY_BASE(0x30));
3796 sav.reg_3EC = b43_read16(dev, 0x3EC);
3798 b43_phy_write(dev, B43_PHY_BASE(0x30), 0xFF);
3799 b43_write16(dev, 0x3EC, 0x3F3F);
3800 } else if (phy->gmode || phy->rev >= 2) {
3801 sav.phy_rfover = b43_phy_read(dev, B43_PHY_RFOVER);
3802 sav.phy_rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
3803 sav.phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
3804 sav.phy_analogoverval =
3805 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
3806 sav.phy_crs0 = b43_phy_read(dev, B43_PHY_CRS0);
3807 sav.phy_classctl = b43_phy_read(dev, B43_PHY_CLASSCTL);
3809 b43_phy_write(dev, B43_PHY_ANALOGOVER,
3810 b43_phy_read(dev, B43_PHY_ANALOGOVER)
3812 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3813 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL)
3815 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
3817 b43_phy_write(dev, B43_PHY_CLASSCTL,
3818 b43_phy_read(dev, B43_PHY_CLASSCTL)
3820 if (has_loopback_gain(phy)) {
3821 sav.phy_lo_mask = b43_phy_read(dev, B43_PHY_LO_MASK);
3822 sav.phy_lo_ctl = b43_phy_read(dev, B43_PHY_LO_CTL);
3825 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
3827 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
3828 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
3831 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3832 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3834 b43_phy_write(dev, B43_PHY_RFOVER,
3835 radio2050_rfover_val(dev, B43_PHY_RFOVER, 0));
3837 b43_write16(dev, 0x3E2, b43_read16(dev, 0x3E2) | 0x8000);
3839 sav.phy_syncctl = b43_phy_read(dev, B43_PHY_SYNCCTL);
3840 b43_phy_write(dev, B43_PHY_SYNCCTL, b43_phy_read(dev, B43_PHY_SYNCCTL)
3842 sav.reg_3E6 = b43_read16(dev, 0x3E6);
3843 sav.reg_3F4 = b43_read16(dev, 0x3F4);
3845 if (phy->analog == 0) {
3846 b43_write16(dev, 0x03E6, 0x0122);
3848 if (phy->analog >= 2) {
3849 b43_phy_write(dev, B43_PHY_BASE(0x03),
3850 (b43_phy_read(dev, B43_PHY_BASE(0x03))
3853 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3854 (b43_read16(dev, B43_MMIO_CHANNEL_EXT) | 0x2000));
3857 rcc = b43_radio_core_calibration_value(dev);
3859 if (phy->type == B43_PHYTYPE_B)
3860 b43_radio_write16(dev, 0x78, 0x26);
3861 if (phy->gmode || phy->rev >= 2) {
3862 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3863 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3866 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFAF);
3867 b43_phy_write(dev, B43_PHY_BASE(0x2B), 0x1403);
3868 if (phy->gmode || phy->rev >= 2) {
3869 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3870 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3873 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFA0);
3874 b43_radio_write16(dev, 0x51, b43_radio_read16(dev, 0x51)
3876 if (phy->radio_rev == 8) {
3877 b43_radio_write16(dev, 0x43, 0x1F);
3879 b43_radio_write16(dev, 0x52, 0);
3880 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
3881 & 0xFFF0) | 0x0009);
3883 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3885 for (i = 0; i < 16; i++) {
3886 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0480);
3887 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3888 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3889 if (phy->gmode || phy->rev >= 2) {
3890 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3891 radio2050_rfover_val(dev,
3895 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3897 if (phy->gmode || phy->rev >= 2) {
3898 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3899 radio2050_rfover_val(dev,
3903 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3905 if (phy->gmode || phy->rev >= 2) {
3906 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3907 radio2050_rfover_val(dev,
3911 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3913 tmp1 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3914 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3915 if (phy->gmode || phy->rev >= 2) {
3916 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3917 radio2050_rfover_val(dev,
3921 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3925 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3929 for (i = 0; i < 16; i++) {
3930 radio78 = ((flip_4bit(i) << 1) | 0x20);
3931 b43_radio_write16(dev, 0x78, radio78);
3933 for (j = 0; j < 16; j++) {
3934 b43_phy_write(dev, B43_PHY_BASE(0x5A), 0x0D80);
3935 b43_phy_write(dev, B43_PHY_BASE(0x59), 0xC810);
3936 b43_phy_write(dev, B43_PHY_BASE(0x58), 0x000D);
3937 if (phy->gmode || phy->rev >= 2) {
3938 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3939 radio2050_rfover_val(dev,
3944 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3946 if (phy->gmode || phy->rev >= 2) {
3947 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3948 radio2050_rfover_val(dev,
3953 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3955 if (phy->gmode || phy->rev >= 2) {
3956 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3957 radio2050_rfover_val(dev,
3962 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3964 tmp2 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3965 b43_phy_write(dev, B43_PHY_BASE(0x58), 0);
3966 if (phy->gmode || phy->rev >= 2) {
3967 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3968 radio2050_rfover_val(dev,
3973 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3981 /* Restore the registers */
3982 b43_phy_write(dev, B43_PHY_PGACTL, sav.phy_pgactl);
3983 b43_radio_write16(dev, 0x51, sav.radio_51);
3984 b43_radio_write16(dev, 0x52, sav.radio_52);
3985 b43_radio_write16(dev, 0x43, sav.radio_43);
3986 b43_phy_write(dev, B43_PHY_BASE(0x5A), sav.phy_base_5A);
3987 b43_phy_write(dev, B43_PHY_BASE(0x59), sav.phy_base_59);
3988 b43_phy_write(dev, B43_PHY_BASE(0x58), sav.phy_base_58);
3989 b43_write16(dev, 0x3E6, sav.reg_3E6);
3990 if (phy->analog != 0)
3991 b43_write16(dev, 0x3F4, sav.reg_3F4);
3992 b43_phy_write(dev, B43_PHY_SYNCCTL, sav.phy_syncctl);
3993 b43_synth_pu_workaround(dev, phy->channel);
3994 if (phy->type == B43_PHYTYPE_B) {
3995 b43_phy_write(dev, B43_PHY_BASE(0x30), sav.phy_base_30);
3996 b43_write16(dev, 0x3EC, sav.reg_3EC);
3997 } else if (phy->gmode) {
3998 b43_write16(dev, B43_MMIO_PHY_RADIO,
3999 b43_read16(dev, B43_MMIO_PHY_RADIO)
4001 b43_phy_write(dev, B43_PHY_RFOVER, sav.phy_rfover);
4002 b43_phy_write(dev, B43_PHY_RFOVERVAL, sav.phy_rfoverval);
4003 b43_phy_write(dev, B43_PHY_ANALOGOVER, sav.phy_analogover);
4004 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
4005 sav.phy_analogoverval);
4006 b43_phy_write(dev, B43_PHY_CRS0, sav.phy_crs0);
4007 b43_phy_write(dev, B43_PHY_CLASSCTL, sav.phy_classctl);
4008 if (has_loopback_gain(phy)) {
4009 b43_phy_write(dev, B43_PHY_LO_MASK, sav.phy_lo_mask);
4010 b43_phy_write(dev, B43_PHY_LO_CTL, sav.phy_lo_ctl);
4021 void b43_radio_init2060(struct b43_wldev *dev)
4025 b43_radio_write16(dev, 0x0004, 0x00C0);
4026 b43_radio_write16(dev, 0x0005, 0x0008);
4027 b43_radio_write16(dev, 0x0009, 0x0040);
4028 b43_radio_write16(dev, 0x0005, 0x00AA);
4029 b43_radio_write16(dev, 0x0032, 0x008F);
4030 b43_radio_write16(dev, 0x0006, 0x008F);
4031 b43_radio_write16(dev, 0x0034, 0x008F);
4032 b43_radio_write16(dev, 0x002C, 0x0007);
4033 b43_radio_write16(dev, 0x0082, 0x0080);
4034 b43_radio_write16(dev, 0x0080, 0x0000);
4035 b43_radio_write16(dev, 0x003F, 0x00DA);
4036 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
4037 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0010);
4038 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
4039 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
4040 msleep(1); /* delay 400usec */
4042 b43_radio_write16(dev, 0x0081,
4043 (b43_radio_read16(dev, 0x0081) & ~0x0020) | 0x0010);
4044 msleep(1); /* delay 400usec */
4046 b43_radio_write16(dev, 0x0005,
4047 (b43_radio_read16(dev, 0x0005) & ~0x0008) | 0x0008);
4048 b43_radio_write16(dev, 0x0085, b43_radio_read16(dev, 0x0085) & ~0x0010);
4049 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
4050 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0040);
4051 b43_radio_write16(dev, 0x0081,
4052 (b43_radio_read16(dev, 0x0081) & ~0x0040) | 0x0040);
4053 b43_radio_write16(dev, 0x0005,
4054 (b43_radio_read16(dev, 0x0081) & ~0x0008) | 0x0008);
4055 b43_phy_write(dev, 0x0063, 0xDDC6);
4056 b43_phy_write(dev, 0x0069, 0x07BE);
4057 b43_phy_write(dev, 0x006A, 0x0000);
4059 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_A, 0);
4065 static inline u16 freq_r3A_value(u16 frequency)
4069 if (frequency < 5091)
4071 else if (frequency < 5321)
4073 else if (frequency < 5806)
4081 void b43_radio_set_tx_iq(struct b43_wldev *dev)
4083 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
4084 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
4085 u16 tmp = b43_radio_read16(dev, 0x001E);
4088 for (i = 0; i < 5; i++) {
4089 for (j = 0; j < 5; j++) {
4090 if (tmp == (data_high[i] << 4 | data_low[j])) {
4091 b43_phy_write(dev, 0x0069,
4092 (i - j) << 8 | 0x00C0);
4099 int b43_radio_selectchannel(struct b43_wldev *dev,
4100 u8 channel, int synthetic_pu_workaround)
4102 struct b43_phy *phy = &dev->phy;
4107 if (channel == 0xFF) {
4108 switch (phy->type) {
4110 channel = B43_DEFAULT_CHANNEL_A;
4114 channel = B43_DEFAULT_CHANNEL_BG;
4121 /* First we set the channel radio code to prevent the
4122 * firmware from sending ghost packets.
4124 channelcookie = channel;
4125 if (phy->type == B43_PHYTYPE_A)
4126 channelcookie |= 0x100;
4127 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
4129 if (phy->type == B43_PHYTYPE_A) {
4132 freq = channel2freq_a(channel);
4134 r8 = b43_radio_read16(dev, 0x0008);
4135 b43_write16(dev, 0x03F0, freq);
4136 b43_radio_write16(dev, 0x0008, r8);
4138 //TODO: write max channel TX power? to Radio 0x2D
4139 tmp = b43_radio_read16(dev, 0x002E);
4141 //TODO: OR tmp with the Power out estimation for this channel?
4142 b43_radio_write16(dev, 0x002E, tmp);
4144 if (freq >= 4920 && freq <= 5500) {
4146 * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
4147 * = (freq * 0.025862069
4149 r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
4151 b43_radio_write16(dev, 0x0007, (r8 << 4) | r8);
4152 b43_radio_write16(dev, 0x0020, (r8 << 4) | r8);
4153 b43_radio_write16(dev, 0x0021, (r8 << 4) | r8);
4154 b43_radio_write16(dev, 0x0022, (b43_radio_read16(dev, 0x0022)
4155 & 0x000F) | (r8 << 4));
4156 b43_radio_write16(dev, 0x002A, (r8 << 4));
4157 b43_radio_write16(dev, 0x002B, (r8 << 4));
4158 b43_radio_write16(dev, 0x0008, (b43_radio_read16(dev, 0x0008)
4159 & 0x00F0) | (r8 << 4));
4160 b43_radio_write16(dev, 0x0029, (b43_radio_read16(dev, 0x0029)
4161 & 0xFF0F) | 0x00B0);
4162 b43_radio_write16(dev, 0x0035, 0x00AA);
4163 b43_radio_write16(dev, 0x0036, 0x0085);
4164 b43_radio_write16(dev, 0x003A, (b43_radio_read16(dev, 0x003A)
4166 freq_r3A_value(freq));
4167 b43_radio_write16(dev, 0x003D,
4168 b43_radio_read16(dev, 0x003D) & 0x00FF);
4169 b43_radio_write16(dev, 0x0081, (b43_radio_read16(dev, 0x0081)
4170 & 0xFF7F) | 0x0080);
4171 b43_radio_write16(dev, 0x0035,
4172 b43_radio_read16(dev, 0x0035) & 0xFFEF);
4173 b43_radio_write16(dev, 0x0035, (b43_radio_read16(dev, 0x0035)
4174 & 0xFFEF) | 0x0010);
4175 b43_radio_set_tx_iq(dev);
4176 //TODO: TSSI2dbm workaround
4177 b43_phy_xmitpower(dev); //FIXME correct?
4179 if ((channel < 1) || (channel > 14))
4182 if (synthetic_pu_workaround)
4183 b43_synth_pu_workaround(dev, channel);
4185 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
4187 if (channel == 14) {
4188 if (dev->dev->bus->sprom.r1.country_code ==
4189 SSB_SPROM1CCODE_JAPAN)
4191 b43_hf_read(dev) & ~B43_HF_ACPR);
4194 b43_hf_read(dev) | B43_HF_ACPR);
4195 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
4196 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
4199 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
4200 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
4205 phy->channel = channel;
4206 /* Wait for the radio to tune to the channel and stabilize. */
4212 /* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
4213 static u16 b43_get_txgain_base_band(u16 txpower)
4217 B43_WARN_ON(txpower > 63);
4221 else if (txpower >= 49)
4223 else if (txpower >= 44)
4231 /* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
4232 static u16 b43_get_txgain_freq_power_amp(u16 txpower)
4236 B43_WARN_ON(txpower > 63);
4240 else if (txpower >= 25)
4242 else if (txpower >= 20)
4244 else if (txpower >= 12)
4252 /* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
4253 static u16 b43_get_txgain_dac(u16 txpower)
4257 B43_WARN_ON(txpower > 63);
4261 else if (txpower >= 49)
4263 else if (txpower >= 44)
4265 else if (txpower >= 32)
4267 else if (txpower >= 25)
4269 else if (txpower >= 20)
4271 else if (txpower >= 12)
4279 static void b43_radio_set_txpower_a(struct b43_wldev *dev, u16 txpower)
4281 struct b43_phy *phy = &dev->phy;
4282 u16 pamp, base, dac, t;
4284 txpower = limit_value(txpower, 0, 63);
4286 pamp = b43_get_txgain_freq_power_amp(txpower);
4289 b43_phy_write(dev, 0x0019, pamp);
4291 base = b43_get_txgain_base_band(txpower);
4293 b43_phy_write(dev, 0x0017, base | 0x0020);
4295 t = b43_ofdmtab_read16(dev, 0x3000, 1);
4298 dac = b43_get_txgain_dac(txpower);
4302 b43_ofdmtab_write16(dev, 0x3000, 1, dac);
4304 phy->txpwr_offset = txpower;
4306 //TODO: FuncPlaceholder (Adjust BB loft cancel)
4309 void b43_radio_turn_on(struct b43_wldev *dev)
4311 struct b43_phy *phy = &dev->phy;
4320 switch (phy->type) {
4322 b43_radio_write16(dev, 0x0004, 0x00C0);
4323 b43_radio_write16(dev, 0x0005, 0x0008);
4324 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) & 0xFFF7);
4325 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) & 0xFFF7);
4326 b43_radio_init2060(dev);
4330 b43_phy_write(dev, 0x0015, 0x8000);
4331 b43_phy_write(dev, 0x0015, 0xCC00);
4332 b43_phy_write(dev, 0x0015, (phy->gmode ? 0x00C0 : 0x0000));
4333 if (phy->radio_off_context.valid) {
4334 /* Restore the RFover values. */
4335 b43_phy_write(dev, B43_PHY_RFOVER,
4336 phy->radio_off_context.rfover);
4337 b43_phy_write(dev, B43_PHY_RFOVERVAL,
4338 phy->radio_off_context.rfoverval);
4339 phy->radio_off_context.valid = 0;
4341 channel = phy->channel;
4342 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_BG, 1);
4343 err |= b43_radio_selectchannel(dev, channel, 0);
4352 void b43_radio_turn_off(struct b43_wldev *dev, bool force)
4354 struct b43_phy *phy = &dev->phy;
4356 if (!phy->radio_on && !force)
4359 if (phy->type == B43_PHYTYPE_A) {
4360 b43_radio_write16(dev, 0x0004, 0x00FF);
4361 b43_radio_write16(dev, 0x0005, 0x00FB);
4362 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) | 0x0008);
4363 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) | 0x0008);
4365 if (phy->type == B43_PHYTYPE_G && dev->dev->id.revision >= 5) {
4366 u16 rfover, rfoverval;
4368 rfover = b43_phy_read(dev, B43_PHY_RFOVER);
4369 rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
4371 phy->radio_off_context.rfover = rfover;
4372 phy->radio_off_context.rfoverval = rfoverval;
4373 phy->radio_off_context.valid = 1;
4375 b43_phy_write(dev, B43_PHY_RFOVER, rfover | 0x008C);
4376 b43_phy_write(dev, B43_PHY_RFOVERVAL, rfoverval & 0xFF73);
4378 b43_phy_write(dev, 0x0015, 0xAA00);