3 Broadcom B43 wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
7 Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
8 Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
9 Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
24 Boston, MA 02110-1301, USA.
28 #include <linux/delay.h>
30 #include <linux/types.h>
41 static const s8 b43_tssi2dbm_b_table[] = {
42 0x4D, 0x4C, 0x4B, 0x4A,
43 0x4A, 0x49, 0x48, 0x47,
44 0x47, 0x46, 0x45, 0x45,
45 0x44, 0x43, 0x42, 0x42,
46 0x41, 0x40, 0x3F, 0x3E,
47 0x3D, 0x3C, 0x3B, 0x3A,
48 0x39, 0x38, 0x37, 0x36,
49 0x35, 0x34, 0x32, 0x31,
50 0x30, 0x2F, 0x2D, 0x2C,
51 0x2B, 0x29, 0x28, 0x26,
52 0x25, 0x23, 0x21, 0x1F,
53 0x1D, 0x1A, 0x17, 0x14,
54 0x10, 0x0C, 0x06, 0x00,
60 static const s8 b43_tssi2dbm_g_table[] = {
79 const u8 b43_radio_channel_codes_bg[] = {
86 static void b43_phy_initg(struct b43_wldev *dev);
88 /* Reverse the bits of a 4bit value.
89 * Example: 1101 is flipped 1011
91 static u16 flip_4bit(u16 value)
95 B43_WARN_ON(value & ~0x000F);
97 flipped |= (value & 0x0001) << 3;
98 flipped |= (value & 0x0002) << 1;
99 flipped |= (value & 0x0004) >> 1;
100 flipped |= (value & 0x0008) >> 3;
105 static void generate_rfatt_list(struct b43_wldev *dev,
106 struct b43_rfatt_list *list)
108 struct b43_phy *phy = &dev->phy;
110 /* APHY.rev < 5 || GPHY.rev < 6 */
111 static const struct b43_rfatt rfatt_0[] = {
112 {.att = 3,.with_padmix = 0,},
113 {.att = 1,.with_padmix = 0,},
114 {.att = 5,.with_padmix = 0,},
115 {.att = 7,.with_padmix = 0,},
116 {.att = 9,.with_padmix = 0,},
117 {.att = 2,.with_padmix = 0,},
118 {.att = 0,.with_padmix = 0,},
119 {.att = 4,.with_padmix = 0,},
120 {.att = 6,.with_padmix = 0,},
121 {.att = 8,.with_padmix = 0,},
122 {.att = 1,.with_padmix = 1,},
123 {.att = 2,.with_padmix = 1,},
124 {.att = 3,.with_padmix = 1,},
125 {.att = 4,.with_padmix = 1,},
127 /* Radio.rev == 8 && Radio.version == 0x2050 */
128 static const struct b43_rfatt rfatt_1[] = {
129 {.att = 2,.with_padmix = 1,},
130 {.att = 4,.with_padmix = 1,},
131 {.att = 6,.with_padmix = 1,},
132 {.att = 8,.with_padmix = 1,},
133 {.att = 10,.with_padmix = 1,},
134 {.att = 12,.with_padmix = 1,},
135 {.att = 14,.with_padmix = 1,},
138 static const struct b43_rfatt rfatt_2[] = {
139 {.att = 0,.with_padmix = 1,},
140 {.att = 2,.with_padmix = 1,},
141 {.att = 4,.with_padmix = 1,},
142 {.att = 6,.with_padmix = 1,},
143 {.att = 8,.with_padmix = 1,},
144 {.att = 9,.with_padmix = 1,},
145 {.att = 9,.with_padmix = 1,},
148 if ((phy->type == B43_PHYTYPE_A && phy->rev < 5) ||
149 (phy->type == B43_PHYTYPE_G && phy->rev < 6)) {
151 list->list = rfatt_0;
152 list->len = ARRAY_SIZE(rfatt_0);
157 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
159 list->list = rfatt_1;
160 list->len = ARRAY_SIZE(rfatt_1);
166 list->list = rfatt_2;
167 list->len = ARRAY_SIZE(rfatt_2);
172 static void generate_bbatt_list(struct b43_wldev *dev,
173 struct b43_bbatt_list *list)
175 static const struct b43_bbatt bbatt_0[] = {
187 list->list = bbatt_0;
188 list->len = ARRAY_SIZE(bbatt_0);
193 bool b43_has_hardware_pctl(struct b43_phy *phy)
195 if (!phy->hardware_power_control)
212 static void b43_shm_clear_tssi(struct b43_wldev *dev)
214 struct b43_phy *phy = &dev->phy;
218 b43_shm_write16(dev, B43_SHM_SHARED, 0x0068, 0x7F7F);
219 b43_shm_write16(dev, B43_SHM_SHARED, 0x006a, 0x7F7F);
223 b43_shm_write16(dev, B43_SHM_SHARED, 0x0058, 0x7F7F);
224 b43_shm_write16(dev, B43_SHM_SHARED, 0x005a, 0x7F7F);
225 b43_shm_write16(dev, B43_SHM_SHARED, 0x0070, 0x7F7F);
226 b43_shm_write16(dev, B43_SHM_SHARED, 0x0072, 0x7F7F);
231 /* Lock the PHY registers against concurrent access from the microcode.
232 * This lock is nonrecursive. */
233 void b43_phy_lock(struct b43_wldev *dev)
236 B43_WARN_ON(dev->phy.phy_locked);
237 dev->phy.phy_locked = 1;
239 B43_WARN_ON(dev->dev->id.revision < 3);
241 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
242 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
245 void b43_phy_unlock(struct b43_wldev *dev)
248 B43_WARN_ON(!dev->phy.phy_locked);
249 dev->phy.phy_locked = 0;
251 B43_WARN_ON(dev->dev->id.revision < 3);
253 if (!b43_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
254 b43_power_saving_ctl_bits(dev, 0);
257 /* Different PHYs require different register routing flags.
258 * This adjusts (and does sanity checks on) the routing flags.
260 static inline u16 adjust_phyreg_for_phytype(struct b43_phy *phy,
261 u16 offset, struct b43_wldev *dev)
263 if (phy->type == B43_PHYTYPE_A) {
264 /* OFDM registers are base-registers for the A-PHY. */
265 if ((offset & B43_PHYROUTE) == B43_PHYROUTE_OFDM_GPHY) {
266 offset &= ~B43_PHYROUTE;
267 offset |= B43_PHYROUTE_BASE;
272 if ((offset & B43_PHYROUTE) == B43_PHYROUTE_EXT_GPHY) {
273 /* Ext-G registers are only available on G-PHYs */
274 if (phy->type != B43_PHYTYPE_G) {
275 b43err(dev->wl, "Invalid EXT-G PHY access at "
276 "0x%04X on PHY type %u\n", offset, phy->type);
280 if ((offset & B43_PHYROUTE) == B43_PHYROUTE_N_BMODE) {
281 /* N-BMODE registers are only available on N-PHYs */
282 if (phy->type != B43_PHYTYPE_N) {
283 b43err(dev->wl, "Invalid N-BMODE PHY access at "
284 "0x%04X on PHY type %u\n", offset, phy->type);
288 #endif /* B43_DEBUG */
293 u16 b43_phy_read(struct b43_wldev * dev, u16 offset)
295 struct b43_phy *phy = &dev->phy;
297 offset = adjust_phyreg_for_phytype(phy, offset, dev);
298 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
299 return b43_read16(dev, B43_MMIO_PHY_DATA);
302 void b43_phy_write(struct b43_wldev *dev, u16 offset, u16 val)
304 struct b43_phy *phy = &dev->phy;
306 offset = adjust_phyreg_for_phytype(phy, offset, dev);
307 b43_write16(dev, B43_MMIO_PHY_CONTROL, offset);
308 b43_write16(dev, B43_MMIO_PHY_DATA, val);
311 void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
313 b43_phy_write(dev, offset,
314 b43_phy_read(dev, offset) & mask);
317 void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set)
319 b43_phy_write(dev, offset,
320 b43_phy_read(dev, offset) | set);
323 void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
325 b43_phy_write(dev, offset,
326 (b43_phy_read(dev, offset) & mask) | set);
329 /* Adjust the transmission power output (G-PHY) */
330 void b43_set_txpower_g(struct b43_wldev *dev,
331 const struct b43_bbatt *bbatt,
332 const struct b43_rfatt *rfatt, u8 tx_control)
334 struct b43_phy *phy = &dev->phy;
335 struct b43_txpower_lo_control *lo = phy->lo_control;
337 u16 tx_bias, tx_magn;
341 tx_bias = lo->tx_bias;
342 tx_magn = lo->tx_magn;
343 if (unlikely(tx_bias == 0xFF))
346 /* Save the values for later */
347 phy->tx_control = tx_control;
348 memcpy(&phy->rfatt, rfatt, sizeof(*rfatt));
349 memcpy(&phy->bbatt, bbatt, sizeof(*bbatt));
351 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
352 b43dbg(dev->wl, "Tuning TX-power to bbatt(%u), "
353 "rfatt(%u), tx_control(0x%02X), "
354 "tx_bias(0x%02X), tx_magn(0x%02X)\n",
355 bb, rf, tx_control, tx_bias, tx_magn);
358 b43_phy_set_baseband_attenuation(dev, bb);
359 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_RFATT, rf);
360 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
361 b43_radio_write16(dev, 0x43,
362 (rf & 0x000F) | (tx_control & 0x0070));
364 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
365 & 0xFFF0) | (rf & 0x000F));
366 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
367 & ~0x0070) | (tx_control &
370 if (has_tx_magnification(phy)) {
371 b43_radio_write16(dev, 0x52, tx_magn | tx_bias);
373 b43_radio_write16(dev, 0x52, (b43_radio_read16(dev, 0x52)
374 & 0xFFF0) | (tx_bias & 0x000F));
376 if (phy->type == B43_PHYTYPE_G)
377 b43_lo_g_adjust(dev);
380 static void default_baseband_attenuation(struct b43_wldev *dev,
381 struct b43_bbatt *bb)
383 struct b43_phy *phy = &dev->phy;
385 if (phy->radio_ver == 0x2050 && phy->radio_rev < 6)
391 static void default_radio_attenuation(struct b43_wldev *dev,
392 struct b43_rfatt *rf)
394 struct ssb_bus *bus = dev->dev->bus;
395 struct b43_phy *phy = &dev->phy;
399 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM &&
400 bus->boardinfo.type == SSB_BOARD_BCM4309G) {
401 if (bus->boardinfo.rev < 0x43) {
404 } else if (bus->boardinfo.rev < 0x51) {
410 if (phy->type == B43_PHYTYPE_A) {
415 switch (phy->radio_ver) {
417 switch (phy->radio_rev) {
424 switch (phy->radio_rev) {
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 ==
442 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
443 && bus->boardinfo.type == SSB_BOARD_BCM4309G
444 && bus->boardinfo.rev >= 30)
451 if (phy->type == B43_PHYTYPE_G) {
452 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM
453 && bus->boardinfo.type == SSB_BOARD_BCM4309G
454 && bus->boardinfo.rev >= 30)
456 else if (bus->boardinfo.vendor ==
458 && bus->boardinfo.type ==
461 else if (bus->chip_id == 0x4320)
492 static u16 default_tx_control(struct b43_wldev *dev)
494 struct b43_phy *phy = &dev->phy;
496 if (phy->radio_ver != 0x2050)
498 if (phy->radio_rev == 1)
499 return B43_TXCTL_PA2DB | B43_TXCTL_TXMIX;
500 if (phy->radio_rev < 6)
501 return B43_TXCTL_PA2DB;
502 if (phy->radio_rev == 8)
503 return B43_TXCTL_TXMIX;
507 /* This func is called "PHY calibrate" in the specs... */
508 void b43_phy_early_init(struct b43_wldev *dev)
510 struct b43_phy *phy = &dev->phy;
511 struct b43_txpower_lo_control *lo = phy->lo_control;
513 default_baseband_attenuation(dev, &phy->bbatt);
514 default_radio_attenuation(dev, &phy->rfatt);
515 phy->tx_control = (default_tx_control(dev) << 4);
517 /* Commit previous writes */
518 b43_read32(dev, B43_MMIO_MACCTL);
520 if (phy->type == B43_PHYTYPE_B || phy->type == B43_PHYTYPE_G) {
521 generate_rfatt_list(dev, &lo->rfatt_list);
522 generate_bbatt_list(dev, &lo->bbatt_list);
524 if (phy->type == B43_PHYTYPE_G && phy->rev == 1) {
525 /* Workaround: Temporarly disable gmode through the early init
526 * phase, as the gmode stuff is not needed for phy rev 1 */
528 b43_wireless_core_reset(dev, 0);
531 b43_wireless_core_reset(dev, B43_TMSLOW_GMODE);
535 /* GPHY_TSSI_Power_Lookup_Table_Init */
536 static void b43_gphy_tssi_power_lt_init(struct b43_wldev *dev)
538 struct b43_phy *phy = &dev->phy;
542 for (i = 0; i < 32; i++)
543 b43_ofdmtab_write16(dev, 0x3C20, i, phy->tssi2dbm[i]);
544 for (i = 32; i < 64; i++)
545 b43_ofdmtab_write16(dev, 0x3C00, i - 32, phy->tssi2dbm[i]);
546 for (i = 0; i < 64; i += 2) {
547 value = (u16) phy->tssi2dbm[i];
548 value |= ((u16) phy->tssi2dbm[i + 1]) << 8;
549 b43_phy_write(dev, 0x380 + (i / 2), value);
553 /* GPHY_Gain_Lookup_Table_Init */
554 static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
556 struct b43_phy *phy = &dev->phy;
557 struct b43_txpower_lo_control *lo = phy->lo_control;
562 if (!lo->lo_measured) {
563 b43_phy_write(dev, 0x3FF, 0);
567 for (rf = 0; rf < lo->rfatt_list.len; rf++) {
568 for (bb = 0; bb < lo->bbatt_list.len; bb++) {
569 if (nr_written >= 0x40)
571 tmp = lo->bbatt_list.list[bb].att;
573 if (phy->radio_rev == 8)
577 tmp |= lo->rfatt_list.list[rf].att;
578 b43_phy_write(dev, 0x3C0 + nr_written, tmp);
584 /* GPHY_DC_Lookup_Table */
585 void b43_gphy_dc_lt_init(struct b43_wldev *dev)
587 struct b43_phy *phy = &dev->phy;
588 struct b43_txpower_lo_control *lo = phy->lo_control;
589 struct b43_loctl *loctl0;
590 struct b43_loctl *loctl1;
592 int rf_offset, bb_offset;
595 for (i = 0; i < lo->rfatt_list.len + lo->bbatt_list.len; i += 2) {
596 rf_offset = i / lo->rfatt_list.len;
597 bb_offset = i % lo->rfatt_list.len;
599 loctl0 = b43_get_lo_g_ctl(dev, &lo->rfatt_list.list[rf_offset],
600 &lo->bbatt_list.list[bb_offset]);
601 if (i + 1 < lo->rfatt_list.len * lo->bbatt_list.len) {
602 rf_offset = (i + 1) / lo->rfatt_list.len;
603 bb_offset = (i + 1) % lo->rfatt_list.len;
606 b43_get_lo_g_ctl(dev,
607 &lo->rfatt_list.list[rf_offset],
608 &lo->bbatt_list.list[bb_offset]);
612 tmp = ((u16) loctl0->q & 0xF);
613 tmp |= ((u16) loctl0->i & 0xF) << 4;
614 tmp |= ((u16) loctl1->q & 0xF) << 8;
615 tmp |= ((u16) loctl1->i & 0xF) << 12; //FIXME?
616 b43_phy_write(dev, 0x3A0 + (i / 2), tmp);
620 static void hardware_pctl_init_aphy(struct b43_wldev *dev)
625 static void hardware_pctl_init_gphy(struct b43_wldev *dev)
627 struct b43_phy *phy = &dev->phy;
629 b43_phy_write(dev, 0x0036, (b43_phy_read(dev, 0x0036) & 0xFFC0)
630 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
631 b43_phy_write(dev, 0x0478, (b43_phy_read(dev, 0x0478) & 0xFF00)
632 | (phy->tgt_idle_tssi - phy->cur_idle_tssi));
633 b43_gphy_tssi_power_lt_init(dev);
634 b43_gphy_gain_lt_init(dev);
635 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) & 0xFFBF);
636 b43_phy_write(dev, 0x0014, 0x0000);
638 B43_WARN_ON(phy->rev < 6);
639 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
641 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478)
643 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801)
646 b43_gphy_dc_lt_init(dev);
649 /* HardwarePowerControl init for A and G PHY */
650 static void b43_hardware_pctl_init(struct b43_wldev *dev)
652 struct b43_phy *phy = &dev->phy;
654 if (!b43_has_hardware_pctl(phy)) {
655 /* No hardware power control */
656 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_HWPCTL);
659 /* Init the hwpctl related hardware */
662 hardware_pctl_init_aphy(dev);
665 hardware_pctl_init_gphy(dev);
670 /* Enable hardware pctl in firmware. */
671 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_HWPCTL);
674 static void b43_hardware_pctl_early_init(struct b43_wldev *dev)
676 struct b43_phy *phy = &dev->phy;
678 if (!b43_has_hardware_pctl(phy)) {
679 b43_phy_write(dev, 0x047A, 0xC111);
683 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036) & 0xFEFF);
684 b43_phy_write(dev, 0x002F, 0x0202);
685 b43_phy_write(dev, 0x047C, b43_phy_read(dev, 0x047C) | 0x0002);
686 b43_phy_write(dev, 0x047A, b43_phy_read(dev, 0x047A) | 0xF000);
687 if (phy->radio_ver == 0x2050 && phy->radio_rev == 8) {
688 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
690 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
692 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
694 b43_phy_write(dev, 0x002E, 0xC07F);
695 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
698 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
700 b43_phy_write(dev, 0x0036, b43_phy_read(dev, 0x0036)
702 b43_phy_write(dev, 0x005D, b43_phy_read(dev, 0x005D)
704 b43_phy_write(dev, 0x004F, b43_phy_read(dev, 0x004F)
706 b43_phy_write(dev, 0x004E, (b43_phy_read(dev, 0x004E)
708 b43_phy_write(dev, 0x002E, 0xC07F);
709 b43_phy_write(dev, 0x047A, (b43_phy_read(dev, 0x047A)
714 /* Intialize B/G PHY power control
715 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
717 static void b43_phy_init_pctl(struct b43_wldev *dev)
719 struct ssb_bus *bus = dev->dev->bus;
720 struct b43_phy *phy = &dev->phy;
721 struct b43_rfatt old_rfatt;
722 struct b43_bbatt old_bbatt;
723 u8 old_tx_control = 0;
725 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
726 (bus->boardinfo.type == SSB_BOARD_BU4306))
729 b43_phy_write(dev, 0x0028, 0x8018);
731 /* This does something with the Analog... */
732 b43_write16(dev, B43_MMIO_PHY0, b43_read16(dev, B43_MMIO_PHY0)
735 if (phy->type == B43_PHYTYPE_G && !phy->gmode)
737 b43_hardware_pctl_early_init(dev);
738 if (phy->cur_idle_tssi == 0) {
739 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
740 b43_radio_write16(dev, 0x0076,
741 (b43_radio_read16(dev, 0x0076)
744 struct b43_rfatt rfatt;
745 struct b43_bbatt bbatt;
747 memcpy(&old_rfatt, &phy->rfatt, sizeof(old_rfatt));
748 memcpy(&old_bbatt, &phy->bbatt, sizeof(old_bbatt));
749 old_tx_control = phy->tx_control;
752 if (phy->radio_rev == 8) {
754 rfatt.with_padmix = 1;
757 rfatt.with_padmix = 0;
759 b43_set_txpower_g(dev, &bbatt, &rfatt, 0);
761 b43_dummy_transmission(dev);
762 phy->cur_idle_tssi = b43_phy_read(dev, B43_PHY_ITSSI);
764 /* Current-Idle-TSSI sanity check. */
765 if (abs(phy->cur_idle_tssi - phy->tgt_idle_tssi) >= 20) {
767 "!WARNING! Idle-TSSI phy->cur_idle_tssi "
768 "measuring failed. (cur=%d, tgt=%d). Disabling TX power "
769 "adjustment.\n", phy->cur_idle_tssi,
771 phy->cur_idle_tssi = 0;
774 if (phy->radio_ver == 0x2050 && phy->analog == 0) {
775 b43_radio_write16(dev, 0x0076,
776 b43_radio_read16(dev, 0x0076)
779 b43_set_txpower_g(dev, &old_bbatt,
780 &old_rfatt, old_tx_control);
783 b43_hardware_pctl_init(dev);
784 b43_shm_clear_tssi(dev);
787 static void b43_phy_rssiagc(struct b43_wldev *dev, u8 enable)
791 if (dev->phy.rev < 3) {
793 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++) {
794 b43_ofdmtab_write16(dev,
795 B43_OFDMTAB_LNAHPFGAIN1, i, 0xFFF8);
796 b43_ofdmtab_write16(dev,
797 B43_OFDMTAB_WRSSI, i, 0xFFF8);
800 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++) {
801 b43_ofdmtab_write16(dev,
802 B43_OFDMTAB_LNAHPFGAIN1, i, b43_tab_rssiagc1[i]);
803 b43_ofdmtab_write16(dev,
804 B43_OFDMTAB_WRSSI, i, b43_tab_rssiagc1[i]);
808 for (i = 0; i < B43_TAB_RSSIAGC1_SIZE; i++)
809 b43_ofdmtab_write16(dev,
810 B43_OFDMTAB_WRSSI, i, 0x0820);
812 for (i = 0; i < B43_TAB_RSSIAGC2_SIZE; i++)
813 b43_ofdmtab_write16(dev,
814 B43_OFDMTAB_WRSSI, i, b43_tab_rssiagc2[i]);
818 static void b43_phy_ww(struct b43_wldev *dev)
820 u16 b, curr_s, best_s = 0xFFFF;
823 b43_phy_write(dev, B43_PHY_CRS0,
824 b43_phy_read(dev, B43_PHY_CRS0) & ~B43_PHY_CRS0_EN);
825 b43_phy_write(dev, B43_PHY_OFDM(0x1B),
826 b43_phy_read(dev, B43_PHY_OFDM(0x1B)) | 0x1000);
827 b43_phy_write(dev, B43_PHY_OFDM(0x82),
828 (b43_phy_read(dev, B43_PHY_OFDM(0x82)) & 0xF0FF) | 0x0300);
829 b43_radio_write16(dev, 0x0009,
830 b43_radio_read16(dev, 0x0009) | 0x0080);
831 b43_radio_write16(dev, 0x0012,
832 (b43_radio_read16(dev, 0x0012) & 0xFFFC) | 0x0002);
833 b43_wa_initgains(dev);
834 b43_phy_write(dev, B43_PHY_OFDM(0xBA), 0x3ED5);
835 b = b43_phy_read(dev, B43_PHY_PWRDOWN);
836 b43_phy_write(dev, B43_PHY_PWRDOWN, (b & 0xFFF8) | 0x0005);
837 b43_radio_write16(dev, 0x0004,
838 b43_radio_read16(dev, 0x0004) | 0x0004);
839 for (i = 0x10; i <= 0x20; i++) {
840 b43_radio_write16(dev, 0x0013, i);
841 curr_s = b43_phy_read(dev, B43_PHY_OTABLEQ) & 0x00FF;
845 } else if (curr_s >= 0x0080)
846 curr_s = 0x0100 - curr_s;
850 b43_phy_write(dev, B43_PHY_PWRDOWN, b);
851 b43_radio_write16(dev, 0x0004,
852 b43_radio_read16(dev, 0x0004) & 0xFFFB);
853 b43_radio_write16(dev, 0x0013, best_s);
854 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1_R1, 0, 0xFFEC);
855 b43_phy_write(dev, B43_PHY_OFDM(0xB7), 0x1E80);
856 b43_phy_write(dev, B43_PHY_OFDM(0xB6), 0x1C00);
857 b43_phy_write(dev, B43_PHY_OFDM(0xB5), 0x0EC0);
858 b43_phy_write(dev, B43_PHY_OFDM(0xB2), 0x00C0);
859 b43_phy_write(dev, B43_PHY_OFDM(0xB9), 0x1FFF);
860 b43_phy_write(dev, B43_PHY_OFDM(0xBB),
861 (b43_phy_read(dev, B43_PHY_OFDM(0xBB)) & 0xF000) | 0x0053);
862 b43_phy_write(dev, B43_PHY_OFDM61,
863 (b43_phy_read(dev, B43_PHY_OFDM61 & 0xFE1F)) | 0x0120);
864 b43_phy_write(dev, B43_PHY_OFDM(0x13),
865 (b43_phy_read(dev, B43_PHY_OFDM(0x13)) & 0x0FFF) | 0x3000);
866 b43_phy_write(dev, B43_PHY_OFDM(0x14),
867 (b43_phy_read(dev, B43_PHY_OFDM(0x14)) & 0x0FFF) | 0x3000);
868 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 6, 0x0017);
869 for (i = 0; i < 6; i++)
870 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, i, 0x000F);
871 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0D, 0x000E);
872 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0E, 0x0011);
873 b43_ofdmtab_write16(dev, B43_OFDMTAB_AGC1, 0x0F, 0x0013);
874 b43_phy_write(dev, B43_PHY_OFDM(0x33), 0x5030);
875 b43_phy_write(dev, B43_PHY_CRS0,
876 b43_phy_read(dev, B43_PHY_CRS0) | B43_PHY_CRS0_EN);
879 /* Initialize APHY. This is also called for the GPHY in some cases. */
880 static void b43_phy_inita(struct b43_wldev *dev)
882 struct ssb_bus *bus = dev->dev->bus;
883 struct b43_phy *phy = &dev->phy;
888 if (phy->type == B43_PHYTYPE_A)
889 b43_phy_write(dev, B43_PHY_OFDM(0x1B),
890 b43_phy_read(dev, B43_PHY_OFDM(0x1B)) & ~0x1000);
891 if (b43_phy_read(dev, B43_PHY_ENCORE) & B43_PHY_ENCORE_EN)
892 b43_phy_write(dev, B43_PHY_ENCORE,
893 b43_phy_read(dev, B43_PHY_ENCORE) | 0x0010);
895 b43_phy_write(dev, B43_PHY_ENCORE,
896 b43_phy_read(dev, B43_PHY_ENCORE) & ~0x1010);
901 if (phy->type == B43_PHYTYPE_A) {
902 if (phy->gmode && (phy->rev < 3))
903 b43_phy_write(dev, 0x0034,
904 b43_phy_read(dev, 0x0034) | 0x0001);
905 b43_phy_rssiagc(dev, 0);
907 b43_phy_write(dev, B43_PHY_CRS0,
908 b43_phy_read(dev, B43_PHY_CRS0) | B43_PHY_CRS0_EN);
910 b43_radio_init2060(dev);
912 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
913 ((bus->boardinfo.type == SSB_BOARD_BU4306) ||
914 (bus->boardinfo.type == SSB_BOARD_BU4309))) {
921 hardware_pctl_init_aphy(dev);
923 //TODO: radar detection
926 if ((phy->type == B43_PHYTYPE_G) &&
927 (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)) {
928 b43_phy_write(dev, B43_PHY_OFDM(0x6E),
929 (b43_phy_read(dev, B43_PHY_OFDM(0x6E))
934 static void b43_phy_initb2(struct b43_wldev *dev)
936 struct b43_phy *phy = &dev->phy;
939 b43_write16(dev, 0x03EC, 0x3F22);
940 b43_phy_write(dev, 0x0020, 0x301C);
941 b43_phy_write(dev, 0x0026, 0x0000);
942 b43_phy_write(dev, 0x0030, 0x00C6);
943 b43_phy_write(dev, 0x0088, 0x3E00);
945 for (offset = 0x0089; offset < 0x00A7; offset++) {
946 b43_phy_write(dev, offset, val);
949 b43_phy_write(dev, 0x03E4, 0x3000);
950 b43_radio_selectchannel(dev, phy->channel, 0);
951 if (phy->radio_ver != 0x2050) {
952 b43_radio_write16(dev, 0x0075, 0x0080);
953 b43_radio_write16(dev, 0x0079, 0x0081);
955 b43_radio_write16(dev, 0x0050, 0x0020);
956 b43_radio_write16(dev, 0x0050, 0x0023);
957 if (phy->radio_ver == 0x2050) {
958 b43_radio_write16(dev, 0x0050, 0x0020);
959 b43_radio_write16(dev, 0x005A, 0x0070);
960 b43_radio_write16(dev, 0x005B, 0x007B);
961 b43_radio_write16(dev, 0x005C, 0x00B0);
962 b43_radio_write16(dev, 0x007A, 0x000F);
963 b43_phy_write(dev, 0x0038, 0x0677);
964 b43_radio_init2050(dev);
966 b43_phy_write(dev, 0x0014, 0x0080);
967 b43_phy_write(dev, 0x0032, 0x00CA);
968 b43_phy_write(dev, 0x0032, 0x00CC);
969 b43_phy_write(dev, 0x0035, 0x07C2);
970 b43_lo_b_measure(dev);
971 b43_phy_write(dev, 0x0026, 0xCC00);
972 if (phy->radio_ver != 0x2050)
973 b43_phy_write(dev, 0x0026, 0xCE00);
974 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1000);
975 b43_phy_write(dev, 0x002A, 0x88A3);
976 if (phy->radio_ver != 0x2050)
977 b43_phy_write(dev, 0x002A, 0x88C2);
978 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
979 b43_phy_init_pctl(dev);
982 static void b43_phy_initb4(struct b43_wldev *dev)
984 struct b43_phy *phy = &dev->phy;
987 b43_write16(dev, 0x03EC, 0x3F22);
988 b43_phy_write(dev, 0x0020, 0x301C);
989 b43_phy_write(dev, 0x0026, 0x0000);
990 b43_phy_write(dev, 0x0030, 0x00C6);
991 b43_phy_write(dev, 0x0088, 0x3E00);
993 for (offset = 0x0089; offset < 0x00A7; offset++) {
994 b43_phy_write(dev, offset, val);
997 b43_phy_write(dev, 0x03E4, 0x3000);
998 b43_radio_selectchannel(dev, phy->channel, 0);
999 if (phy->radio_ver != 0x2050) {
1000 b43_radio_write16(dev, 0x0075, 0x0080);
1001 b43_radio_write16(dev, 0x0079, 0x0081);
1003 b43_radio_write16(dev, 0x0050, 0x0020);
1004 b43_radio_write16(dev, 0x0050, 0x0023);
1005 if (phy->radio_ver == 0x2050) {
1006 b43_radio_write16(dev, 0x0050, 0x0020);
1007 b43_radio_write16(dev, 0x005A, 0x0070);
1008 b43_radio_write16(dev, 0x005B, 0x007B);
1009 b43_radio_write16(dev, 0x005C, 0x00B0);
1010 b43_radio_write16(dev, 0x007A, 0x000F);
1011 b43_phy_write(dev, 0x0038, 0x0677);
1012 b43_radio_init2050(dev);
1014 b43_phy_write(dev, 0x0014, 0x0080);
1015 b43_phy_write(dev, 0x0032, 0x00CA);
1016 if (phy->radio_ver == 0x2050)
1017 b43_phy_write(dev, 0x0032, 0x00E0);
1018 b43_phy_write(dev, 0x0035, 0x07C2);
1020 b43_lo_b_measure(dev);
1022 b43_phy_write(dev, 0x0026, 0xCC00);
1023 if (phy->radio_ver == 0x2050)
1024 b43_phy_write(dev, 0x0026, 0xCE00);
1025 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1100);
1026 b43_phy_write(dev, 0x002A, 0x88A3);
1027 if (phy->radio_ver == 0x2050)
1028 b43_phy_write(dev, 0x002A, 0x88C2);
1029 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1030 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1031 b43_calc_nrssi_slope(dev);
1032 b43_calc_nrssi_threshold(dev);
1034 b43_phy_init_pctl(dev);
1037 static void b43_phy_initb5(struct b43_wldev *dev)
1039 struct ssb_bus *bus = dev->dev->bus;
1040 struct b43_phy *phy = &dev->phy;
1044 if (phy->analog == 1) {
1045 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A)
1048 if ((bus->boardinfo.vendor != SSB_BOARDVENDOR_BCM) &&
1049 (bus->boardinfo.type != SSB_BOARD_BU4306)) {
1051 for (offset = 0x00A8; offset < 0x00C7; offset++) {
1052 b43_phy_write(dev, offset, value);
1056 b43_phy_write(dev, 0x0035, (b43_phy_read(dev, 0x0035) & 0xF0FF)
1058 if (phy->radio_ver == 0x2050)
1059 b43_phy_write(dev, 0x0038, 0x0667);
1061 if (phy->gmode || phy->rev >= 2) {
1062 if (phy->radio_ver == 0x2050) {
1063 b43_radio_write16(dev, 0x007A,
1064 b43_radio_read16(dev, 0x007A)
1066 b43_radio_write16(dev, 0x0051,
1067 b43_radio_read16(dev, 0x0051)
1070 b43_write16(dev, B43_MMIO_PHY_RADIO, 0x0000);
1072 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1073 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1075 b43_phy_write(dev, 0x001C, 0x186A);
1077 b43_phy_write(dev, 0x0013,
1078 (b43_phy_read(dev, 0x0013) & 0x00FF) | 0x1900);
1079 b43_phy_write(dev, 0x0035,
1080 (b43_phy_read(dev, 0x0035) & 0xFFC0) | 0x0064);
1081 b43_phy_write(dev, 0x005D,
1082 (b43_phy_read(dev, 0x005D) & 0xFF80) | 0x000A);
1085 if (dev->bad_frames_preempt) {
1086 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
1088 B43_PHY_RADIO_BITFIELD) | (1 << 11));
1091 if (phy->analog == 1) {
1092 b43_phy_write(dev, 0x0026, 0xCE00);
1093 b43_phy_write(dev, 0x0021, 0x3763);
1094 b43_phy_write(dev, 0x0022, 0x1BC3);
1095 b43_phy_write(dev, 0x0023, 0x06F9);
1096 b43_phy_write(dev, 0x0024, 0x037E);
1098 b43_phy_write(dev, 0x0026, 0xCC00);
1099 b43_phy_write(dev, 0x0030, 0x00C6);
1100 b43_write16(dev, 0x03EC, 0x3F22);
1102 if (phy->analog == 1)
1103 b43_phy_write(dev, 0x0020, 0x3E1C);
1105 b43_phy_write(dev, 0x0020, 0x301C);
1107 if (phy->analog == 0)
1108 b43_write16(dev, 0x03E4, 0x3000);
1110 old_channel = phy->channel;
1111 /* Force to channel 7, even if not supported. */
1112 b43_radio_selectchannel(dev, 7, 0);
1114 if (phy->radio_ver != 0x2050) {
1115 b43_radio_write16(dev, 0x0075, 0x0080);
1116 b43_radio_write16(dev, 0x0079, 0x0081);
1119 b43_radio_write16(dev, 0x0050, 0x0020);
1120 b43_radio_write16(dev, 0x0050, 0x0023);
1122 if (phy->radio_ver == 0x2050) {
1123 b43_radio_write16(dev, 0x0050, 0x0020);
1124 b43_radio_write16(dev, 0x005A, 0x0070);
1127 b43_radio_write16(dev, 0x005B, 0x007B);
1128 b43_radio_write16(dev, 0x005C, 0x00B0);
1130 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0007);
1132 b43_radio_selectchannel(dev, old_channel, 0);
1134 b43_phy_write(dev, 0x0014, 0x0080);
1135 b43_phy_write(dev, 0x0032, 0x00CA);
1136 b43_phy_write(dev, 0x002A, 0x88A3);
1138 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1140 if (phy->radio_ver == 0x2050)
1141 b43_radio_write16(dev, 0x005D, 0x000D);
1143 b43_write16(dev, 0x03E4, (b43_read16(dev, 0x03E4) & 0xFFC0) | 0x0004);
1146 static void b43_phy_initb6(struct b43_wldev *dev)
1148 struct b43_phy *phy = &dev->phy;
1152 b43_phy_write(dev, 0x003E, 0x817A);
1153 b43_radio_write16(dev, 0x007A,
1154 (b43_radio_read16(dev, 0x007A) | 0x0058));
1155 if (phy->radio_rev == 4 || phy->radio_rev == 5) {
1156 b43_radio_write16(dev, 0x51, 0x37);
1157 b43_radio_write16(dev, 0x52, 0x70);
1158 b43_radio_write16(dev, 0x53, 0xB3);
1159 b43_radio_write16(dev, 0x54, 0x9B);
1160 b43_radio_write16(dev, 0x5A, 0x88);
1161 b43_radio_write16(dev, 0x5B, 0x88);
1162 b43_radio_write16(dev, 0x5D, 0x88);
1163 b43_radio_write16(dev, 0x5E, 0x88);
1164 b43_radio_write16(dev, 0x7D, 0x88);
1165 b43_hf_write(dev, b43_hf_read(dev)
1166 | B43_HF_TSSIRPSMW);
1168 B43_WARN_ON(phy->radio_rev == 6 || phy->radio_rev == 7); /* We had code for these revs here... */
1169 if (phy->radio_rev == 8) {
1170 b43_radio_write16(dev, 0x51, 0);
1171 b43_radio_write16(dev, 0x52, 0x40);
1172 b43_radio_write16(dev, 0x53, 0xB7);
1173 b43_radio_write16(dev, 0x54, 0x98);
1174 b43_radio_write16(dev, 0x5A, 0x88);
1175 b43_radio_write16(dev, 0x5B, 0x6B);
1176 b43_radio_write16(dev, 0x5C, 0x0F);
1177 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_ALTIQ) {
1178 b43_radio_write16(dev, 0x5D, 0xFA);
1179 b43_radio_write16(dev, 0x5E, 0xD8);
1181 b43_radio_write16(dev, 0x5D, 0xF5);
1182 b43_radio_write16(dev, 0x5E, 0xB8);
1184 b43_radio_write16(dev, 0x0073, 0x0003);
1185 b43_radio_write16(dev, 0x007D, 0x00A8);
1186 b43_radio_write16(dev, 0x007C, 0x0001);
1187 b43_radio_write16(dev, 0x007E, 0x0008);
1190 for (offset = 0x0088; offset < 0x0098; offset++) {
1191 b43_phy_write(dev, offset, val);
1195 for (offset = 0x0098; offset < 0x00A8; offset++) {
1196 b43_phy_write(dev, offset, val);
1200 for (offset = 0x00A8; offset < 0x00C8; offset++) {
1201 b43_phy_write(dev, offset, (val & 0x3F3F));
1204 if (phy->type == B43_PHYTYPE_G) {
1205 b43_radio_write16(dev, 0x007A,
1206 b43_radio_read16(dev, 0x007A) | 0x0020);
1207 b43_radio_write16(dev, 0x0051,
1208 b43_radio_read16(dev, 0x0051) | 0x0004);
1209 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x0100);
1210 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x2000);
1211 b43_phy_write(dev, 0x5B, 0);
1212 b43_phy_write(dev, 0x5C, 0);
1215 old_channel = phy->channel;
1216 if (old_channel >= 8)
1217 b43_radio_selectchannel(dev, 1, 0);
1219 b43_radio_selectchannel(dev, 13, 0);
1221 b43_radio_write16(dev, 0x0050, 0x0020);
1222 b43_radio_write16(dev, 0x0050, 0x0023);
1224 if (phy->radio_rev < 6 || phy->radio_rev == 8) {
1225 b43_radio_write16(dev, 0x7C, (b43_radio_read16(dev, 0x7C)
1227 b43_radio_write16(dev, 0x50, 0x20);
1229 if (phy->radio_rev <= 2) {
1230 b43_radio_write16(dev, 0x7C, 0x20);
1231 b43_radio_write16(dev, 0x5A, 0x70);
1232 b43_radio_write16(dev, 0x5B, 0x7B);
1233 b43_radio_write16(dev, 0x5C, 0xB0);
1235 b43_radio_write16(dev, 0x007A,
1236 (b43_radio_read16(dev, 0x007A) & 0x00F8) | 0x0007);
1238 b43_radio_selectchannel(dev, old_channel, 0);
1240 b43_phy_write(dev, 0x0014, 0x0200);
1241 if (phy->radio_rev >= 6)
1242 b43_phy_write(dev, 0x2A, 0x88C2);
1244 b43_phy_write(dev, 0x2A, 0x8AC0);
1245 b43_phy_write(dev, 0x0038, 0x0668);
1246 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1247 if (phy->radio_rev <= 5) {
1248 b43_phy_write(dev, 0x5D, (b43_phy_read(dev, 0x5D)
1249 & 0xFF80) | 0x0003);
1251 if (phy->radio_rev <= 2)
1252 b43_radio_write16(dev, 0x005D, 0x000D);
1254 if (phy->analog == 4) {
1255 b43_write16(dev, 0x3E4, 9);
1256 b43_phy_write(dev, 0x61, b43_phy_read(dev, 0x61)
1259 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0)
1262 if (phy->type == B43_PHYTYPE_B) {
1263 b43_write16(dev, 0x03E6, 0x8140);
1264 b43_phy_write(dev, 0x0016, 0x0410);
1265 b43_phy_write(dev, 0x0017, 0x0820);
1266 b43_phy_write(dev, 0x0062, 0x0007);
1267 b43_radio_init2050(dev);
1268 b43_lo_g_measure(dev);
1269 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1270 b43_calc_nrssi_slope(dev);
1271 b43_calc_nrssi_threshold(dev);
1273 b43_phy_init_pctl(dev);
1274 } else if (phy->type == B43_PHYTYPE_G)
1275 b43_write16(dev, 0x03E6, 0x0);
1278 static void b43_calc_loopback_gain(struct b43_wldev *dev)
1280 struct b43_phy *phy = &dev->phy;
1281 u16 backup_phy[16] = { 0 };
1282 u16 backup_radio[3];
1284 u16 i, j, loop_i_max;
1286 u16 loop1_outer_done, loop1_inner_done;
1288 backup_phy[0] = b43_phy_read(dev, B43_PHY_CRS0);
1289 backup_phy[1] = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
1290 backup_phy[2] = b43_phy_read(dev, B43_PHY_RFOVER);
1291 backup_phy[3] = b43_phy_read(dev, B43_PHY_RFOVERVAL);
1292 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1293 backup_phy[4] = b43_phy_read(dev, B43_PHY_ANALOGOVER);
1294 backup_phy[5] = b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
1296 backup_phy[6] = b43_phy_read(dev, B43_PHY_CCK(0x5A));
1297 backup_phy[7] = b43_phy_read(dev, B43_PHY_CCK(0x59));
1298 backup_phy[8] = b43_phy_read(dev, B43_PHY_CCK(0x58));
1299 backup_phy[9] = b43_phy_read(dev, B43_PHY_CCK(0x0A));
1300 backup_phy[10] = b43_phy_read(dev, B43_PHY_CCK(0x03));
1301 backup_phy[11] = b43_phy_read(dev, B43_PHY_LO_MASK);
1302 backup_phy[12] = b43_phy_read(dev, B43_PHY_LO_CTL);
1303 backup_phy[13] = b43_phy_read(dev, B43_PHY_CCK(0x2B));
1304 backup_phy[14] = b43_phy_read(dev, B43_PHY_PGACTL);
1305 backup_phy[15] = b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
1306 backup_bband = phy->bbatt.att;
1307 backup_radio[0] = b43_radio_read16(dev, 0x52);
1308 backup_radio[1] = b43_radio_read16(dev, 0x43);
1309 backup_radio[2] = b43_radio_read16(dev, 0x7A);
1311 b43_phy_write(dev, B43_PHY_CRS0,
1312 b43_phy_read(dev, B43_PHY_CRS0) & 0x3FFF);
1313 b43_phy_write(dev, B43_PHY_CCKBBANDCFG,
1314 b43_phy_read(dev, B43_PHY_CCKBBANDCFG) | 0x8000);
1315 b43_phy_write(dev, B43_PHY_RFOVER,
1316 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0002);
1317 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1318 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFD);
1319 b43_phy_write(dev, B43_PHY_RFOVER,
1320 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0001);
1321 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1322 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xFFFE);
1323 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1324 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1325 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0001);
1326 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1328 B43_PHY_ANALOGOVERVAL) & 0xFFFE);
1329 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1330 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0002);
1331 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1333 B43_PHY_ANALOGOVERVAL) & 0xFFFD);
1335 b43_phy_write(dev, B43_PHY_RFOVER,
1336 b43_phy_read(dev, B43_PHY_RFOVER) | 0x000C);
1337 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1338 b43_phy_read(dev, B43_PHY_RFOVERVAL) | 0x000C);
1339 b43_phy_write(dev, B43_PHY_RFOVER,
1340 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0030);
1341 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1342 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1345 b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0780);
1346 b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
1347 b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
1349 b43_phy_write(dev, B43_PHY_CCK(0x0A),
1350 b43_phy_read(dev, B43_PHY_CCK(0x0A)) | 0x2000);
1351 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1352 b43_phy_write(dev, B43_PHY_ANALOGOVER,
1353 b43_phy_read(dev, B43_PHY_ANALOGOVER) | 0x0004);
1354 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
1356 B43_PHY_ANALOGOVERVAL) & 0xFFFB);
1358 b43_phy_write(dev, B43_PHY_CCK(0x03),
1359 (b43_phy_read(dev, B43_PHY_CCK(0x03))
1362 if (phy->radio_rev == 8) {
1363 b43_radio_write16(dev, 0x43, 0x000F);
1365 b43_radio_write16(dev, 0x52, 0);
1366 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
1369 b43_phy_set_baseband_attenuation(dev, 11);
1372 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
1374 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
1375 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
1377 b43_phy_write(dev, B43_PHY_CCK(0x2B),
1378 (b43_phy_read(dev, B43_PHY_CCK(0x2B))
1380 b43_phy_write(dev, B43_PHY_CCK(0x2B),
1381 (b43_phy_read(dev, B43_PHY_CCK(0x2B))
1384 b43_phy_write(dev, B43_PHY_RFOVER,
1385 b43_phy_read(dev, B43_PHY_RFOVER) | 0x0100);
1386 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1387 b43_phy_read(dev, B43_PHY_RFOVERVAL) & 0xCFFF);
1389 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_EXTLNA) {
1390 if (phy->rev >= 7) {
1391 b43_phy_write(dev, B43_PHY_RFOVER,
1392 b43_phy_read(dev, B43_PHY_RFOVER)
1394 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1395 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1399 b43_radio_write16(dev, 0x7A, b43_radio_read16(dev, 0x7A)
1403 loop_i_max = (phy->radio_rev == 8) ? 15 : 9;
1404 for (i = 0; i < loop_i_max; i++) {
1405 for (j = 0; j < 16; j++) {
1406 b43_radio_write16(dev, 0x43, i);
1407 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1408 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1409 & 0xF0FF) | (j << 8));
1410 b43_phy_write(dev, B43_PHY_PGACTL,
1411 (b43_phy_read(dev, B43_PHY_PGACTL)
1412 & 0x0FFF) | 0xA000);
1413 b43_phy_write(dev, B43_PHY_PGACTL,
1414 b43_phy_read(dev, B43_PHY_PGACTL)
1417 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1422 loop1_outer_done = i;
1423 loop1_inner_done = j;
1425 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1426 b43_phy_read(dev, B43_PHY_RFOVERVAL)
1429 for (j = j - 8; j < 16; j++) {
1430 b43_phy_write(dev, B43_PHY_RFOVERVAL,
1431 (b43_phy_read(dev, B43_PHY_RFOVERVAL)
1432 & 0xF0FF) | (j << 8));
1433 b43_phy_write(dev, B43_PHY_PGACTL,
1434 (b43_phy_read(dev, B43_PHY_PGACTL)
1435 & 0x0FFF) | 0xA000);
1436 b43_phy_write(dev, B43_PHY_PGACTL,
1437 b43_phy_read(dev, B43_PHY_PGACTL)
1441 if (b43_phy_read(dev, B43_PHY_LO_LEAKAGE) >= 0xDFC)
1448 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
1449 b43_phy_write(dev, B43_PHY_ANALOGOVER, backup_phy[4]);
1450 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, backup_phy[5]);
1452 b43_phy_write(dev, B43_PHY_CCK(0x5A), backup_phy[6]);
1453 b43_phy_write(dev, B43_PHY_CCK(0x59), backup_phy[7]);
1454 b43_phy_write(dev, B43_PHY_CCK(0x58), backup_phy[8]);
1455 b43_phy_write(dev, B43_PHY_CCK(0x0A), backup_phy[9]);
1456 b43_phy_write(dev, B43_PHY_CCK(0x03), backup_phy[10]);
1457 b43_phy_write(dev, B43_PHY_LO_MASK, backup_phy[11]);
1458 b43_phy_write(dev, B43_PHY_LO_CTL, backup_phy[12]);
1459 b43_phy_write(dev, B43_PHY_CCK(0x2B), backup_phy[13]);
1460 b43_phy_write(dev, B43_PHY_PGACTL, backup_phy[14]);
1462 b43_phy_set_baseband_attenuation(dev, backup_bband);
1464 b43_radio_write16(dev, 0x52, backup_radio[0]);
1465 b43_radio_write16(dev, 0x43, backup_radio[1]);
1466 b43_radio_write16(dev, 0x7A, backup_radio[2]);
1468 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2] | 0x0003);
1470 b43_phy_write(dev, B43_PHY_RFOVER, backup_phy[2]);
1471 b43_phy_write(dev, B43_PHY_RFOVERVAL, backup_phy[3]);
1472 b43_phy_write(dev, B43_PHY_CRS0, backup_phy[0]);
1473 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, backup_phy[1]);
1476 ((loop1_inner_done * 6) - (loop1_outer_done * 4)) - 11;
1477 phy->trsw_rx_gain = trsw_rx * 2;
1480 static void b43_phy_initg(struct b43_wldev *dev)
1482 struct b43_phy *phy = &dev->phy;
1486 b43_phy_initb5(dev);
1488 b43_phy_initb6(dev);
1490 if (phy->rev >= 2 || phy->gmode)
1493 if (phy->rev >= 2) {
1494 b43_phy_write(dev, B43_PHY_ANALOGOVER, 0);
1495 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL, 0);
1497 if (phy->rev == 2) {
1498 b43_phy_write(dev, B43_PHY_RFOVER, 0);
1499 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1502 b43_phy_write(dev, B43_PHY_RFOVER, 0x400);
1503 b43_phy_write(dev, B43_PHY_PGACTL, 0xC0);
1505 if (phy->gmode || phy->rev >= 2) {
1506 tmp = b43_phy_read(dev, B43_PHY_VERSION_OFDM);
1507 tmp &= B43_PHYVER_VERSION;
1508 if (tmp == 3 || tmp == 5) {
1509 b43_phy_write(dev, B43_PHY_OFDM(0xC2), 0x1816);
1510 b43_phy_write(dev, B43_PHY_OFDM(0xC3), 0x8006);
1513 b43_phy_write(dev, B43_PHY_OFDM(0xCC),
1514 (b43_phy_read(dev, B43_PHY_OFDM(0xCC))
1515 & 0x00FF) | 0x1F00);
1518 if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2)
1519 b43_phy_write(dev, B43_PHY_OFDM(0x7E), 0x78);
1520 if (phy->radio_rev == 8) {
1521 b43_phy_write(dev, B43_PHY_EXTG(0x01),
1522 b43_phy_read(dev, B43_PHY_EXTG(0x01))
1524 b43_phy_write(dev, B43_PHY_OFDM(0x3E),
1525 b43_phy_read(dev, B43_PHY_OFDM(0x3E))
1528 if (has_loopback_gain(phy))
1529 b43_calc_loopback_gain(dev);
1531 if (phy->radio_rev != 8) {
1532 if (phy->initval == 0xFFFF)
1533 phy->initval = b43_radio_init2050(dev);
1535 b43_radio_write16(dev, 0x0078, phy->initval);
1537 if (phy->lo_control->tx_bias == 0xFF) {
1538 b43_lo_g_measure(dev);
1540 if (has_tx_magnification(phy)) {
1541 b43_radio_write16(dev, 0x52,
1542 (b43_radio_read16(dev, 0x52) & 0xFF00)
1543 | phy->lo_control->tx_bias | phy->
1544 lo_control->tx_magn);
1546 b43_radio_write16(dev, 0x52,
1547 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1548 | phy->lo_control->tx_bias);
1550 if (phy->rev >= 6) {
1551 b43_phy_write(dev, B43_PHY_CCK(0x36),
1552 (b43_phy_read(dev, B43_PHY_CCK(0x36))
1553 & 0x0FFF) | (phy->lo_control->
1556 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)
1557 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x8075);
1559 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x807F);
1561 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x101);
1563 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x202);
1565 if (phy->gmode || phy->rev >= 2) {
1566 b43_lo_g_adjust(dev);
1567 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
1570 if (!(dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI)) {
1571 /* The specs state to update the NRSSI LT with
1572 * the value 0x7FFFFFFF here. I think that is some weird
1573 * compiler optimization in the original driver.
1574 * Essentially, what we do here is resetting all NRSSI LT
1575 * entries to -32 (see the limit_value() in nrssi_hw_update())
1577 b43_nrssi_hw_update(dev, 0xFFFF); //FIXME?
1578 b43_calc_nrssi_threshold(dev);
1579 } else if (phy->gmode || phy->rev >= 2) {
1580 if (phy->nrssi[0] == -1000) {
1581 B43_WARN_ON(phy->nrssi[1] != -1000);
1582 b43_calc_nrssi_slope(dev);
1584 b43_calc_nrssi_threshold(dev);
1586 if (phy->radio_rev == 8)
1587 b43_phy_write(dev, B43_PHY_EXTG(0x05), 0x3230);
1588 b43_phy_init_pctl(dev);
1589 /* FIXME: The spec says in the following if, the 0 should be replaced
1590 'if OFDM may not be used in the current locale'
1591 but OFDM is legal everywhere */
1592 if ((dev->dev->bus->chip_id == 0x4306
1593 && dev->dev->bus->chip_package == 2) || 0) {
1594 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
1596 b43_phy_write(dev, B43_PHY_OFDM(0xC3),
1597 b43_phy_read(dev, B43_PHY_OFDM(0xC3))
1602 /* Set the baseband attenuation value on chip. */
1603 void b43_phy_set_baseband_attenuation(struct b43_wldev *dev,
1604 u16 baseband_attenuation)
1606 struct b43_phy *phy = &dev->phy;
1608 if (phy->analog == 0) {
1609 b43_write16(dev, B43_MMIO_PHY0, (b43_read16(dev, B43_MMIO_PHY0)
1611 baseband_attenuation);
1612 } else if (phy->analog > 1) {
1613 b43_phy_write(dev, B43_PHY_DACCTL,
1614 (b43_phy_read(dev, B43_PHY_DACCTL)
1615 & 0xFFC3) | (baseband_attenuation << 2));
1617 b43_phy_write(dev, B43_PHY_DACCTL,
1618 (b43_phy_read(dev, B43_PHY_DACCTL)
1619 & 0xFF87) | (baseband_attenuation << 3));
1623 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1624 * This function converts a TSSI value to dBm in Q5.2
1626 static s8 b43_phy_estimate_power_out(struct b43_wldev *dev, s8 tssi)
1628 struct b43_phy *phy = &dev->phy;
1632 tmp = (phy->tgt_idle_tssi - phy->cur_idle_tssi + tssi);
1634 switch (phy->type) {
1637 tmp = limit_value(tmp, 0x00, 0xFF);
1638 dbm = phy->tssi2dbm[tmp];
1639 //TODO: There's a FIXME on the specs
1643 tmp = limit_value(tmp, 0x00, 0x3F);
1644 dbm = phy->tssi2dbm[tmp];
1653 void b43_put_attenuation_into_ranges(struct b43_wldev *dev,
1654 int *_bbatt, int *_rfatt)
1656 int rfatt = *_rfatt;
1657 int bbatt = *_bbatt;
1658 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
1660 /* Get baseband and radio attenuation values into their permitted ranges.
1661 * Radio attenuation affects power level 4 times as much as baseband. */
1663 /* Range constants */
1664 const int rf_min = lo->rfatt_list.min_val;
1665 const int rf_max = lo->rfatt_list.max_val;
1666 const int bb_min = lo->bbatt_list.min_val;
1667 const int bb_max = lo->bbatt_list.max_val;
1670 if (rfatt > rf_max && bbatt > bb_max - 4)
1671 break; /* Can not get it into ranges */
1672 if (rfatt < rf_min && bbatt < bb_min + 4)
1673 break; /* Can not get it into ranges */
1674 if (bbatt > bb_max && rfatt > rf_max - 1)
1675 break; /* Can not get it into ranges */
1676 if (bbatt < bb_min && rfatt < rf_min + 1)
1677 break; /* Can not get it into ranges */
1679 if (bbatt > bb_max) {
1684 if (bbatt < bb_min) {
1689 if (rfatt > rf_max) {
1694 if (rfatt < rf_min) {
1702 *_rfatt = limit_value(rfatt, rf_min, rf_max);
1703 *_bbatt = limit_value(bbatt, bb_min, bb_max);
1706 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1707 void b43_phy_xmitpower(struct b43_wldev *dev)
1709 struct ssb_bus *bus = dev->dev->bus;
1710 struct b43_phy *phy = &dev->phy;
1712 if (phy->cur_idle_tssi == 0)
1714 if ((bus->boardinfo.vendor == SSB_BOARDVENDOR_BCM) &&
1715 (bus->boardinfo.type == SSB_BOARD_BU4306))
1717 #ifdef CONFIG_B43_DEBUG
1718 if (phy->manual_txpower_control)
1722 switch (phy->type) {
1723 case B43_PHYTYPE_A:{
1725 //TODO: Nothing for A PHYs yet :-/
1730 case B43_PHYTYPE_G:{
1735 int desired_pwr, estimated_pwr, pwr_adjust;
1736 int rfatt_delta, bbatt_delta;
1740 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x0058);
1741 v0 = (s8) (tmp & 0x00FF);
1742 v1 = (s8) ((tmp & 0xFF00) >> 8);
1743 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x005A);
1744 v2 = (s8) (tmp & 0x00FF);
1745 v3 = (s8) ((tmp & 0xFF00) >> 8);
1748 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
1751 b43_shm_read16(dev, B43_SHM_SHARED, 0x0070);
1752 v0 = (s8) (tmp & 0x00FF);
1753 v1 = (s8) ((tmp & 0xFF00) >> 8);
1755 b43_shm_read16(dev, B43_SHM_SHARED, 0x0072);
1756 v2 = (s8) (tmp & 0x00FF);
1757 v3 = (s8) ((tmp & 0xFF00) >> 8);
1758 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F
1761 v0 = (v0 + 0x20) & 0x3F;
1762 v1 = (v1 + 0x20) & 0x3F;
1763 v2 = (v2 + 0x20) & 0x3F;
1764 v3 = (v3 + 0x20) & 0x3F;
1767 b43_shm_clear_tssi(dev);
1769 average = (v0 + v1 + v2 + v3 + 2) / 4;
1772 && (b43_shm_read16(dev, B43_SHM_SHARED, 0x005E) &
1777 b43_phy_estimate_power_out(dev, average);
1779 max_pwr = dev->dev->bus->sprom.maxpwr_bg;
1780 if ((dev->dev->bus->sprom.boardflags_lo
1781 & B43_BFL_PACTRL) && (phy->type == B43_PHYTYPE_G))
1783 if (unlikely(max_pwr <= 0)) {
1785 "Invalid max-TX-power value in SPROM.\n");
1786 max_pwr = 60; /* fake it */
1787 dev->dev->bus->sprom.maxpwr_bg = max_pwr;
1791 max_pwr = min(REG - dev->dev->bus->sprom.antennagain_bgphy - 0x6, max_pwr)
1792 where REG is the max power as per the regulatory domain
1795 /* Get desired power (in Q5.2) */
1796 desired_pwr = INT_TO_Q52(phy->power_level);
1797 /* And limit it. max_pwr already is Q5.2 */
1798 desired_pwr = limit_value(desired_pwr, 0, max_pwr);
1799 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
1801 "Current TX power output: " Q52_FMT
1802 " dBm, " "Desired TX power output: "
1803 Q52_FMT " dBm\n", Q52_ARG(estimated_pwr),
1804 Q52_ARG(desired_pwr));
1807 /* Calculate the adjustment delta. */
1808 pwr_adjust = desired_pwr - estimated_pwr;
1810 /* RF attenuation delta. */
1811 rfatt_delta = ((pwr_adjust + 7) / 8);
1812 /* Lower attenuation => Bigger power output. Negate it. */
1813 rfatt_delta = -rfatt_delta;
1815 /* Baseband attenuation delta. */
1816 bbatt_delta = pwr_adjust / 2;
1817 /* Lower attenuation => Bigger power output. Negate it. */
1818 bbatt_delta = -bbatt_delta;
1819 /* RF att affects power level 4 times as much as
1820 * Baseband attennuation. Subtract it. */
1821 bbatt_delta -= 4 * rfatt_delta;
1823 /* So do we finally need to adjust something? */
1824 if ((rfatt_delta == 0) && (bbatt_delta == 0)) {
1825 b43_lo_g_ctl_mark_cur_used(dev);
1829 /* Calculate the new attenuation values. */
1830 bbatt = phy->bbatt.att;
1831 bbatt += bbatt_delta;
1832 rfatt = phy->rfatt.att;
1833 rfatt += rfatt_delta;
1835 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
1836 tx_control = phy->tx_control;
1837 if ((phy->radio_ver == 0x2050) && (phy->radio_rev == 2)) {
1839 if (tx_control == 0) {
1845 } else if (dev->dev->bus->sprom.
1848 bbatt += 4 * (rfatt - 2);
1851 } else if (rfatt > 4 && tx_control) {
1862 /* Save the control values */
1863 phy->tx_control = tx_control;
1864 b43_put_attenuation_into_ranges(dev, &bbatt, &rfatt);
1865 phy->rfatt.att = rfatt;
1866 phy->bbatt.att = bbatt;
1868 /* Adjust the hardware */
1870 b43_radio_lock(dev);
1871 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt,
1873 b43_lo_g_ctl_mark_cur_used(dev);
1874 b43_radio_unlock(dev);
1875 b43_phy_unlock(dev);
1879 b43_nphy_xmitpower(dev);
1886 static inline s32 b43_tssi2dbm_ad(s32 num, s32 den)
1891 return (num + den / 2) / den;
1895 s8 b43_tssi2dbm_entry(s8 entry[], u8 index, s16 pab0, s16 pab1, s16 pab2)
1897 s32 m1, m2, f = 256, q, delta;
1900 m1 = b43_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
1901 m2 = max(b43_tssi2dbm_ad(32768 + index * pab2, 256), 1);
1905 q = b43_tssi2dbm_ad(f * 4096 -
1906 b43_tssi2dbm_ad(m2 * f, 16) * f, 2048);
1910 } while (delta >= 2);
1911 entry[index] = limit_value(b43_tssi2dbm_ad(m1 * f, 8192), -127, 128);
1915 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
1916 int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev)
1918 struct b43_phy *phy = &dev->phy;
1919 s16 pab0, pab1, pab2;
1923 if (phy->type == B43_PHYTYPE_A) {
1924 pab0 = (s16) (dev->dev->bus->sprom.pa1b0);
1925 pab1 = (s16) (dev->dev->bus->sprom.pa1b1);
1926 pab2 = (s16) (dev->dev->bus->sprom.pa1b2);
1928 pab0 = (s16) (dev->dev->bus->sprom.pa0b0);
1929 pab1 = (s16) (dev->dev->bus->sprom.pa0b1);
1930 pab2 = (s16) (dev->dev->bus->sprom.pa0b2);
1933 if ((dev->dev->bus->chip_id == 0x4301) && (phy->radio_ver != 0x2050)) {
1934 phy->tgt_idle_tssi = 0x34;
1935 phy->tssi2dbm = b43_tssi2dbm_b_table;
1939 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
1940 pab0 != -1 && pab1 != -1 && pab2 != -1) {
1941 /* The pabX values are set in SPROM. Use them. */
1942 if (phy->type == B43_PHYTYPE_A) {
1943 if ((s8) dev->dev->bus->sprom.itssi_a != 0 &&
1944 (s8) dev->dev->bus->sprom.itssi_a != -1)
1945 phy->tgt_idle_tssi =
1946 (s8) (dev->dev->bus->sprom.itssi_a);
1948 phy->tgt_idle_tssi = 62;
1950 if ((s8) dev->dev->bus->sprom.itssi_bg != 0 &&
1951 (s8) dev->dev->bus->sprom.itssi_bg != -1)
1952 phy->tgt_idle_tssi =
1953 (s8) (dev->dev->bus->sprom.itssi_bg);
1955 phy->tgt_idle_tssi = 62;
1957 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
1958 if (dyn_tssi2dbm == NULL) {
1959 b43err(dev->wl, "Could not allocate memory "
1960 "for tssi2dbm table\n");
1963 for (idx = 0; idx < 64; idx++)
1964 if (b43_tssi2dbm_entry
1965 (dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
1966 phy->tssi2dbm = NULL;
1967 b43err(dev->wl, "Could not generate "
1968 "tssi2dBm table\n");
1969 kfree(dyn_tssi2dbm);
1972 phy->tssi2dbm = dyn_tssi2dbm;
1973 phy->dyn_tssi_tbl = 1;
1975 /* pabX values not set in SPROM. */
1976 switch (phy->type) {
1978 /* APHY needs a generated table. */
1979 phy->tssi2dbm = NULL;
1980 b43err(dev->wl, "Could not generate tssi2dBm "
1981 "table (wrong SPROM info)!\n");
1984 phy->tgt_idle_tssi = 0x34;
1985 phy->tssi2dbm = b43_tssi2dbm_b_table;
1988 phy->tgt_idle_tssi = 0x34;
1989 phy->tssi2dbm = b43_tssi2dbm_g_table;
1997 int b43_phy_init(struct b43_wldev *dev)
1999 struct b43_phy *phy = &dev->phy;
2000 bool unsupported = 0;
2003 switch (phy->type) {
2005 if (phy->rev == 2 || phy->rev == 3)
2013 b43_phy_initb2(dev);
2016 b43_phy_initb4(dev);
2019 b43_phy_initb5(dev);
2022 b43_phy_initb6(dev);
2032 err = b43_phy_initn(dev);
2038 b43err(dev->wl, "Unknown PHYTYPE found\n");
2043 void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2045 struct b43_phy *phy = &dev->phy;
2050 if (antenna == B43_ANTENNA_AUTO0 || antenna == B43_ANTENNA_AUTO1)
2053 hf = b43_hf_read(dev);
2054 hf &= ~B43_HF_ANTDIVHELP;
2055 b43_hf_write(dev, hf);
2057 switch (phy->type) {
2060 tmp = b43_phy_read(dev, B43_PHY_BBANDCFG);
2061 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2062 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2063 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2064 b43_phy_write(dev, B43_PHY_BBANDCFG, tmp);
2067 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2068 if (antenna == B43_ANTENNA_AUTO0)
2069 tmp &= ~B43_PHY_ANTDWELL_AUTODIV1;
2071 tmp |= B43_PHY_ANTDWELL_AUTODIV1;
2072 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2074 if (phy->type == B43_PHYTYPE_G) {
2075 tmp = b43_phy_read(dev, B43_PHY_ANTWRSETT);
2077 tmp |= B43_PHY_ANTWRSETT_ARXDIV;
2079 tmp &= ~B43_PHY_ANTWRSETT_ARXDIV;
2080 b43_phy_write(dev, B43_PHY_ANTWRSETT, tmp);
2081 if (phy->rev >= 2) {
2082 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2083 tmp |= B43_PHY_OFDM61_10;
2084 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2087 b43_phy_read(dev, B43_PHY_DIVSRCHGAINBACK);
2088 tmp = (tmp & 0xFF00) | 0x15;
2089 b43_phy_write(dev, B43_PHY_DIVSRCHGAINBACK,
2092 if (phy->rev == 2) {
2093 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2098 B43_PHY_ADIVRELATED);
2099 tmp = (tmp & 0xFF00) | 8;
2100 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2105 b43_phy_write(dev, B43_PHY_OFDM9B, 0xDC);
2108 tmp = b43_phy_read(dev, B43_PHY_ANTDWELL);
2109 tmp = (tmp & 0xFF00) | 0x24;
2110 b43_phy_write(dev, B43_PHY_ANTDWELL, tmp);
2112 tmp = b43_phy_read(dev, B43_PHY_OFDM61);
2114 b43_phy_write(dev, B43_PHY_OFDM61, tmp);
2115 if (phy->analog == 3) {
2116 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2118 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2121 b43_phy_write(dev, B43_PHY_CLIPPWRDOWNT,
2125 B43_PHY_ADIVRELATED);
2126 tmp = (tmp & 0xFF00) | 8;
2127 b43_phy_write(dev, B43_PHY_ADIVRELATED,
2134 tmp = b43_phy_read(dev, B43_PHY_CCKBBANDCFG);
2135 tmp &= ~B43_PHY_BBANDCFG_RXANT;
2136 tmp |= (autodiv ? B43_ANTENNA_AUTO0 : antenna)
2137 << B43_PHY_BBANDCFG_RXANT_SHIFT;
2138 b43_phy_write(dev, B43_PHY_CCKBBANDCFG, tmp);
2141 b43_nphy_set_rxantenna(dev, antenna);
2147 hf |= B43_HF_ANTDIVHELP;
2148 b43_hf_write(dev, hf);
2151 /* Get the freq, as it has to be written to the device. */
2152 static inline u16 channel2freq_bg(u8 channel)
2154 B43_WARN_ON(!(channel >= 1 && channel <= 14));
2156 return b43_radio_channel_codes_bg[channel - 1];
2159 /* Get the freq, as it has to be written to the device. */
2160 static inline u16 channel2freq_a(u8 channel)
2162 B43_WARN_ON(channel > 200);
2164 return (5000 + 5 * channel);
2167 void b43_radio_lock(struct b43_wldev *dev)
2171 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2172 B43_WARN_ON(macctl & B43_MACCTL_RADIOLOCK);
2173 macctl |= B43_MACCTL_RADIOLOCK;
2174 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2175 /* Commit the write and wait for the device
2176 * to exit any radio register access. */
2177 b43_read32(dev, B43_MMIO_MACCTL);
2181 void b43_radio_unlock(struct b43_wldev *dev)
2185 /* Commit any write */
2186 b43_read16(dev, B43_MMIO_PHY_VER);
2188 macctl = b43_read32(dev, B43_MMIO_MACCTL);
2189 B43_WARN_ON(!(macctl & B43_MACCTL_RADIOLOCK));
2190 macctl &= ~B43_MACCTL_RADIOLOCK;
2191 b43_write32(dev, B43_MMIO_MACCTL, macctl);
2194 u16 b43_radio_read16(struct b43_wldev *dev, u16 offset)
2196 struct b43_phy *phy = &dev->phy;
2198 /* Offset 1 is a 32-bit register. */
2199 B43_WARN_ON(offset == 1);
2201 switch (phy->type) {
2206 if (phy->radio_ver == 0x2053) {
2209 else if (offset < 0x80)
2211 } else if (phy->radio_ver == 0x2050) {
2222 case B43_PHYTYPE_LP:
2223 /* No adjustment required. */
2229 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2230 return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
2233 void b43_radio_write16(struct b43_wldev *dev, u16 offset, u16 val)
2235 /* Offset 1 is a 32-bit register. */
2236 B43_WARN_ON(offset == 1);
2238 b43_write16(dev, B43_MMIO_RADIO_CONTROL, offset);
2239 b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, val);
2242 void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask)
2244 b43_radio_write16(dev, offset,
2245 b43_radio_read16(dev, offset) & mask);
2248 void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set)
2250 b43_radio_write16(dev, offset,
2251 b43_radio_read16(dev, offset) | set);
2254 void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
2256 b43_radio_write16(dev, offset,
2257 (b43_radio_read16(dev, offset) & mask) | set);
2260 static void b43_set_all_gains(struct b43_wldev *dev,
2261 s16 first, s16 second, s16 third)
2263 struct b43_phy *phy = &dev->phy;
2265 u16 start = 0x08, end = 0x18;
2269 if (phy->rev <= 1) {
2274 table = B43_OFDMTAB_GAINX;
2276 table = B43_OFDMTAB_GAINX_R1;
2277 for (i = 0; i < 4; i++)
2278 b43_ofdmtab_write16(dev, table, i, first);
2280 for (i = start; i < end; i++)
2281 b43_ofdmtab_write16(dev, table, i, second);
2284 tmp = ((u16) third << 14) | ((u16) third << 6);
2285 b43_phy_write(dev, 0x04A0,
2286 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | tmp);
2287 b43_phy_write(dev, 0x04A1,
2288 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | tmp);
2289 b43_phy_write(dev, 0x04A2,
2290 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | tmp);
2292 b43_dummy_transmission(dev);
2295 static void b43_set_original_gains(struct b43_wldev *dev)
2297 struct b43_phy *phy = &dev->phy;
2300 u16 start = 0x0008, end = 0x0018;
2302 if (phy->rev <= 1) {
2307 table = B43_OFDMTAB_GAINX;
2309 table = B43_OFDMTAB_GAINX_R1;
2310 for (i = 0; i < 4; i++) {
2312 tmp |= (i & 0x0001) << 1;
2313 tmp |= (i & 0x0002) >> 1;
2315 b43_ofdmtab_write16(dev, table, i, tmp);
2318 for (i = start; i < end; i++)
2319 b43_ofdmtab_write16(dev, table, i, i - start);
2321 b43_phy_write(dev, 0x04A0,
2322 (b43_phy_read(dev, 0x04A0) & 0xBFBF) | 0x4040);
2323 b43_phy_write(dev, 0x04A1,
2324 (b43_phy_read(dev, 0x04A1) & 0xBFBF) | 0x4040);
2325 b43_phy_write(dev, 0x04A2,
2326 (b43_phy_read(dev, 0x04A2) & 0xBFBF) | 0x4000);
2327 b43_dummy_transmission(dev);
2330 /* Synthetic PU workaround */
2331 static void b43_synth_pu_workaround(struct b43_wldev *dev, u8 channel)
2333 struct b43_phy *phy = &dev->phy;
2337 if (phy->radio_ver != 0x2050 || phy->radio_rev >= 6) {
2338 /* We do not need the workaround. */
2342 if (channel <= 10) {
2343 b43_write16(dev, B43_MMIO_CHANNEL,
2344 channel2freq_bg(channel + 4));
2346 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(1));
2349 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
2352 u8 b43_radio_aci_detect(struct b43_wldev *dev, u8 channel)
2354 struct b43_phy *phy = &dev->phy;
2356 u16 saved, rssi, temp;
2359 saved = b43_phy_read(dev, 0x0403);
2360 b43_radio_selectchannel(dev, channel, 0);
2361 b43_phy_write(dev, 0x0403, (saved & 0xFFF8) | 5);
2362 if (phy->aci_hw_rssi)
2363 rssi = b43_phy_read(dev, 0x048A) & 0x3F;
2365 rssi = saved & 0x3F;
2366 /* clamp temp to signed 5bit */
2369 for (i = 0; i < 100; i++) {
2370 temp = (b43_phy_read(dev, 0x047F) >> 8) & 0x3F;
2378 b43_phy_write(dev, 0x0403, saved);
2383 u8 b43_radio_aci_scan(struct b43_wldev * dev)
2385 struct b43_phy *phy = &dev->phy;
2387 unsigned int channel = phy->channel;
2388 unsigned int i, j, start, end;
2390 if (!((phy->type == B43_PHYTYPE_G) && (phy->rev > 0)))
2394 b43_radio_lock(dev);
2395 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2396 b43_phy_write(dev, B43_PHY_G_CRS,
2397 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2398 b43_set_all_gains(dev, 3, 8, 1);
2400 start = (channel - 5 > 0) ? channel - 5 : 1;
2401 end = (channel + 5 < 14) ? channel + 5 : 13;
2403 for (i = start; i <= end; i++) {
2404 if (abs(channel - i) > 2)
2405 ret[i - 1] = b43_radio_aci_detect(dev, i);
2407 b43_radio_selectchannel(dev, channel, 0);
2408 b43_phy_write(dev, 0x0802,
2409 (b43_phy_read(dev, 0x0802) & 0xFFFC) | 0x0003);
2410 b43_phy_write(dev, 0x0403, b43_phy_read(dev, 0x0403) & 0xFFF8);
2411 b43_phy_write(dev, B43_PHY_G_CRS,
2412 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2413 b43_set_original_gains(dev);
2414 for (i = 0; i < 13; i++) {
2417 end = (i + 5 < 13) ? i + 5 : 13;
2418 for (j = i; j < end; j++)
2421 b43_radio_unlock(dev);
2422 b43_phy_unlock(dev);
2424 return ret[channel - 1];
2427 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2428 void b43_nrssi_hw_write(struct b43_wldev *dev, u16 offset, s16 val)
2430 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2432 b43_phy_write(dev, B43_PHY_NRSSILT_DATA, (u16) val);
2435 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2436 s16 b43_nrssi_hw_read(struct b43_wldev *dev, u16 offset)
2440 b43_phy_write(dev, B43_PHY_NRSSILT_CTRL, offset);
2441 val = b43_phy_read(dev, B43_PHY_NRSSILT_DATA);
2446 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2447 void b43_nrssi_hw_update(struct b43_wldev *dev, u16 val)
2452 for (i = 0; i < 64; i++) {
2453 tmp = b43_nrssi_hw_read(dev, i);
2455 tmp = limit_value(tmp, -32, 31);
2456 b43_nrssi_hw_write(dev, i, tmp);
2460 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
2461 void b43_nrssi_mem_update(struct b43_wldev *dev)
2463 struct b43_phy *phy = &dev->phy;
2467 delta = 0x1F - phy->nrssi[0];
2468 for (i = 0; i < 64; i++) {
2469 tmp = (i - delta) * phy->nrssislope;
2472 tmp = limit_value(tmp, 0, 0x3F);
2473 phy->nrssi_lt[i] = tmp;
2477 static void b43_calc_nrssi_offset(struct b43_wldev *dev)
2479 struct b43_phy *phy = &dev->phy;
2480 u16 backup[20] = { 0 };
2485 backup[0] = b43_phy_read(dev, 0x0001);
2486 backup[1] = b43_phy_read(dev, 0x0811);
2487 backup[2] = b43_phy_read(dev, 0x0812);
2488 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2489 backup[3] = b43_phy_read(dev, 0x0814);
2490 backup[4] = b43_phy_read(dev, 0x0815);
2492 backup[5] = b43_phy_read(dev, 0x005A);
2493 backup[6] = b43_phy_read(dev, 0x0059);
2494 backup[7] = b43_phy_read(dev, 0x0058);
2495 backup[8] = b43_phy_read(dev, 0x000A);
2496 backup[9] = b43_phy_read(dev, 0x0003);
2497 backup[10] = b43_radio_read16(dev, 0x007A);
2498 backup[11] = b43_radio_read16(dev, 0x0043);
2500 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) & 0x7FFF);
2501 b43_phy_write(dev, 0x0001,
2502 (b43_phy_read(dev, 0x0001) & 0x3FFF) | 0x4000);
2503 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2504 b43_phy_write(dev, 0x0812,
2505 (b43_phy_read(dev, 0x0812) & 0xFFF3) | 0x0004);
2506 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & ~(0x1 | 0x2));
2507 if (phy->rev >= 6) {
2508 backup[12] = b43_phy_read(dev, 0x002E);
2509 backup[13] = b43_phy_read(dev, 0x002F);
2510 backup[14] = b43_phy_read(dev, 0x080F);
2511 backup[15] = b43_phy_read(dev, 0x0810);
2512 backup[16] = b43_phy_read(dev, 0x0801);
2513 backup[17] = b43_phy_read(dev, 0x0060);
2514 backup[18] = b43_phy_read(dev, 0x0014);
2515 backup[19] = b43_phy_read(dev, 0x0478);
2517 b43_phy_write(dev, 0x002E, 0);
2518 b43_phy_write(dev, 0x002F, 0);
2519 b43_phy_write(dev, 0x080F, 0);
2520 b43_phy_write(dev, 0x0810, 0);
2521 b43_phy_write(dev, 0x0478, b43_phy_read(dev, 0x0478) | 0x0100);
2522 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801) | 0x0040);
2523 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060) | 0x0040);
2524 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014) | 0x0200);
2526 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0070);
2527 b43_radio_write16(dev, 0x007A, b43_radio_read16(dev, 0x007A) | 0x0080);
2530 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2534 for (i = 7; i >= 4; i--) {
2535 b43_radio_write16(dev, 0x007B, i);
2538 (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2541 if (v47F < 31 && saved == 0xFFFF)
2544 if (saved == 0xFFFF)
2547 b43_radio_write16(dev, 0x007A,
2548 b43_radio_read16(dev, 0x007A) & 0x007F);
2549 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2550 b43_phy_write(dev, 0x0814,
2551 b43_phy_read(dev, 0x0814) | 0x0001);
2552 b43_phy_write(dev, 0x0815,
2553 b43_phy_read(dev, 0x0815) & 0xFFFE);
2555 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x000C);
2556 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x000C);
2557 b43_phy_write(dev, 0x0811, b43_phy_read(dev, 0x0811) | 0x0030);
2558 b43_phy_write(dev, 0x0812, b43_phy_read(dev, 0x0812) | 0x0030);
2559 b43_phy_write(dev, 0x005A, 0x0480);
2560 b43_phy_write(dev, 0x0059, 0x0810);
2561 b43_phy_write(dev, 0x0058, 0x000D);
2562 if (phy->rev == 0) {
2563 b43_phy_write(dev, 0x0003, 0x0122);
2565 b43_phy_write(dev, 0x000A, b43_phy_read(dev, 0x000A)
2568 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2569 b43_phy_write(dev, 0x0814,
2570 b43_phy_read(dev, 0x0814) | 0x0004);
2571 b43_phy_write(dev, 0x0815,
2572 b43_phy_read(dev, 0x0815) & 0xFFFB);
2574 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003) & 0xFF9F)
2576 b43_radio_write16(dev, 0x007A,
2577 b43_radio_read16(dev, 0x007A) | 0x000F);
2578 b43_set_all_gains(dev, 3, 0, 1);
2579 b43_radio_write16(dev, 0x0043, (b43_radio_read16(dev, 0x0043)
2580 & 0x00F0) | 0x000F);
2582 v47F = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2586 for (i = 0; i < 4; i++) {
2587 b43_radio_write16(dev, 0x007B, i);
2590 (s16) ((b43_phy_read(dev, 0x047F) >> 8) &
2594 if (v47F > -31 && saved == 0xFFFF)
2597 if (saved == 0xFFFF)
2602 b43_radio_write16(dev, 0x007B, saved);
2604 if (phy->rev >= 6) {
2605 b43_phy_write(dev, 0x002E, backup[12]);
2606 b43_phy_write(dev, 0x002F, backup[13]);
2607 b43_phy_write(dev, 0x080F, backup[14]);
2608 b43_phy_write(dev, 0x0810, backup[15]);
2610 if (phy->rev != 1) { /* Not in specs, but needed to prevent PPC machine check */
2611 b43_phy_write(dev, 0x0814, backup[3]);
2612 b43_phy_write(dev, 0x0815, backup[4]);
2614 b43_phy_write(dev, 0x005A, backup[5]);
2615 b43_phy_write(dev, 0x0059, backup[6]);
2616 b43_phy_write(dev, 0x0058, backup[7]);
2617 b43_phy_write(dev, 0x000A, backup[8]);
2618 b43_phy_write(dev, 0x0003, backup[9]);
2619 b43_radio_write16(dev, 0x0043, backup[11]);
2620 b43_radio_write16(dev, 0x007A, backup[10]);
2621 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) | 0x1 | 0x2);
2622 b43_phy_write(dev, 0x0429, b43_phy_read(dev, 0x0429) | 0x8000);
2623 b43_set_original_gains(dev);
2624 if (phy->rev >= 6) {
2625 b43_phy_write(dev, 0x0801, backup[16]);
2626 b43_phy_write(dev, 0x0060, backup[17]);
2627 b43_phy_write(dev, 0x0014, backup[18]);
2628 b43_phy_write(dev, 0x0478, backup[19]);
2630 b43_phy_write(dev, 0x0001, backup[0]);
2631 b43_phy_write(dev, 0x0812, backup[2]);
2632 b43_phy_write(dev, 0x0811, backup[1]);
2635 void b43_calc_nrssi_slope(struct b43_wldev *dev)
2637 struct b43_phy *phy = &dev->phy;
2638 u16 backup[18] = { 0 };
2642 switch (phy->type) {
2644 backup[0] = b43_radio_read16(dev, 0x007A);
2645 backup[1] = b43_radio_read16(dev, 0x0052);
2646 backup[2] = b43_radio_read16(dev, 0x0043);
2647 backup[3] = b43_phy_read(dev, 0x0030);
2648 backup[4] = b43_phy_read(dev, 0x0026);
2649 backup[5] = b43_phy_read(dev, 0x0015);
2650 backup[6] = b43_phy_read(dev, 0x002A);
2651 backup[7] = b43_phy_read(dev, 0x0020);
2652 backup[8] = b43_phy_read(dev, 0x005A);
2653 backup[9] = b43_phy_read(dev, 0x0059);
2654 backup[10] = b43_phy_read(dev, 0x0058);
2655 backup[11] = b43_read16(dev, 0x03E2);
2656 backup[12] = b43_read16(dev, 0x03E6);
2657 backup[13] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2659 tmp = b43_radio_read16(dev, 0x007A);
2660 tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
2661 b43_radio_write16(dev, 0x007A, tmp);
2662 b43_phy_write(dev, 0x0030, 0x00FF);
2663 b43_write16(dev, 0x03EC, 0x7F7F);
2664 b43_phy_write(dev, 0x0026, 0x0000);
2665 b43_phy_write(dev, 0x0015, b43_phy_read(dev, 0x0015) | 0x0020);
2666 b43_phy_write(dev, 0x002A, 0x08A3);
2667 b43_radio_write16(dev, 0x007A,
2668 b43_radio_read16(dev, 0x007A) | 0x0080);
2670 nrssi0 = (s16) b43_phy_read(dev, 0x0027);
2671 b43_radio_write16(dev, 0x007A,
2672 b43_radio_read16(dev, 0x007A) & 0x007F);
2673 if (phy->rev >= 2) {
2674 b43_write16(dev, 0x03E6, 0x0040);
2675 } else if (phy->rev == 0) {
2676 b43_write16(dev, 0x03E6, 0x0122);
2678 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2680 B43_MMIO_CHANNEL_EXT) & 0x2000);
2682 b43_phy_write(dev, 0x0020, 0x3F3F);
2683 b43_phy_write(dev, 0x0015, 0xF330);
2684 b43_radio_write16(dev, 0x005A, 0x0060);
2685 b43_radio_write16(dev, 0x0043,
2686 b43_radio_read16(dev, 0x0043) & 0x00F0);
2687 b43_phy_write(dev, 0x005A, 0x0480);
2688 b43_phy_write(dev, 0x0059, 0x0810);
2689 b43_phy_write(dev, 0x0058, 0x000D);
2692 nrssi1 = (s16) b43_phy_read(dev, 0x0027);
2693 b43_phy_write(dev, 0x0030, backup[3]);
2694 b43_radio_write16(dev, 0x007A, backup[0]);
2695 b43_write16(dev, 0x03E2, backup[11]);
2696 b43_phy_write(dev, 0x0026, backup[4]);
2697 b43_phy_write(dev, 0x0015, backup[5]);
2698 b43_phy_write(dev, 0x002A, backup[6]);
2699 b43_synth_pu_workaround(dev, phy->channel);
2701 b43_write16(dev, 0x03F4, backup[13]);
2703 b43_phy_write(dev, 0x0020, backup[7]);
2704 b43_phy_write(dev, 0x005A, backup[8]);
2705 b43_phy_write(dev, 0x0059, backup[9]);
2706 b43_phy_write(dev, 0x0058, backup[10]);
2707 b43_radio_write16(dev, 0x0052, backup[1]);
2708 b43_radio_write16(dev, 0x0043, backup[2]);
2710 if (nrssi0 == nrssi1)
2711 phy->nrssislope = 0x00010000;
2713 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2716 phy->nrssi[0] = nrssi0;
2717 phy->nrssi[1] = nrssi1;
2721 if (phy->radio_rev >= 9)
2723 if (phy->radio_rev == 8)
2724 b43_calc_nrssi_offset(dev);
2726 b43_phy_write(dev, B43_PHY_G_CRS,
2727 b43_phy_read(dev, B43_PHY_G_CRS) & 0x7FFF);
2728 b43_phy_write(dev, 0x0802, b43_phy_read(dev, 0x0802) & 0xFFFC);
2729 backup[7] = b43_read16(dev, 0x03E2);
2730 b43_write16(dev, 0x03E2, b43_read16(dev, 0x03E2) | 0x8000);
2731 backup[0] = b43_radio_read16(dev, 0x007A);
2732 backup[1] = b43_radio_read16(dev, 0x0052);
2733 backup[2] = b43_radio_read16(dev, 0x0043);
2734 backup[3] = b43_phy_read(dev, 0x0015);
2735 backup[4] = b43_phy_read(dev, 0x005A);
2736 backup[5] = b43_phy_read(dev, 0x0059);
2737 backup[6] = b43_phy_read(dev, 0x0058);
2738 backup[8] = b43_read16(dev, 0x03E6);
2739 backup[9] = b43_read16(dev, B43_MMIO_CHANNEL_EXT);
2740 if (phy->rev >= 3) {
2741 backup[10] = b43_phy_read(dev, 0x002E);
2742 backup[11] = b43_phy_read(dev, 0x002F);
2743 backup[12] = b43_phy_read(dev, 0x080F);
2744 backup[13] = b43_phy_read(dev, B43_PHY_G_LO_CONTROL);
2745 backup[14] = b43_phy_read(dev, 0x0801);
2746 backup[15] = b43_phy_read(dev, 0x0060);
2747 backup[16] = b43_phy_read(dev, 0x0014);
2748 backup[17] = b43_phy_read(dev, 0x0478);
2749 b43_phy_write(dev, 0x002E, 0);
2750 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, 0);
2755 b43_phy_write(dev, 0x0478,
2756 b43_phy_read(dev, 0x0478)
2758 b43_phy_write(dev, 0x0801,
2759 b43_phy_read(dev, 0x0801)
2764 b43_phy_write(dev, 0x0801,
2765 b43_phy_read(dev, 0x0801)
2769 b43_phy_write(dev, 0x0060, b43_phy_read(dev, 0x0060)
2771 b43_phy_write(dev, 0x0014, b43_phy_read(dev, 0x0014)
2774 b43_radio_write16(dev, 0x007A,
2775 b43_radio_read16(dev, 0x007A) | 0x0070);
2776 b43_set_all_gains(dev, 0, 8, 0);
2777 b43_radio_write16(dev, 0x007A,
2778 b43_radio_read16(dev, 0x007A) & 0x00F7);
2779 if (phy->rev >= 2) {
2780 b43_phy_write(dev, 0x0811,
2781 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
2783 b43_phy_write(dev, 0x0812,
2784 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
2787 b43_radio_write16(dev, 0x007A,
2788 b43_radio_read16(dev, 0x007A) | 0x0080);
2791 nrssi0 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2792 if (nrssi0 >= 0x0020)
2795 b43_radio_write16(dev, 0x007A,
2796 b43_radio_read16(dev, 0x007A) & 0x007F);
2797 if (phy->rev >= 2) {
2798 b43_phy_write(dev, 0x0003, (b43_phy_read(dev, 0x0003)
2799 & 0xFF9F) | 0x0040);
2802 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
2803 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
2805 b43_radio_write16(dev, 0x007A,
2806 b43_radio_read16(dev, 0x007A) | 0x000F);
2807 b43_phy_write(dev, 0x0015, 0xF330);
2808 if (phy->rev >= 2) {
2809 b43_phy_write(dev, 0x0812,
2810 (b43_phy_read(dev, 0x0812) & 0xFFCF) |
2812 b43_phy_write(dev, 0x0811,
2813 (b43_phy_read(dev, 0x0811) & 0xFFCF) |
2817 b43_set_all_gains(dev, 3, 0, 1);
2818 if (phy->radio_rev == 8) {
2819 b43_radio_write16(dev, 0x0043, 0x001F);
2821 tmp = b43_radio_read16(dev, 0x0052) & 0xFF0F;
2822 b43_radio_write16(dev, 0x0052, tmp | 0x0060);
2823 tmp = b43_radio_read16(dev, 0x0043) & 0xFFF0;
2824 b43_radio_write16(dev, 0x0043, tmp | 0x0009);
2826 b43_phy_write(dev, 0x005A, 0x0480);
2827 b43_phy_write(dev, 0x0059, 0x0810);
2828 b43_phy_write(dev, 0x0058, 0x000D);
2830 nrssi1 = (s16) ((b43_phy_read(dev, 0x047F) >> 8) & 0x003F);
2831 if (nrssi1 >= 0x0020)
2833 if (nrssi0 == nrssi1)
2834 phy->nrssislope = 0x00010000;
2836 phy->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
2838 phy->nrssi[0] = nrssi1;
2839 phy->nrssi[1] = nrssi0;
2841 if (phy->rev >= 3) {
2842 b43_phy_write(dev, 0x002E, backup[10]);
2843 b43_phy_write(dev, 0x002F, backup[11]);
2844 b43_phy_write(dev, 0x080F, backup[12]);
2845 b43_phy_write(dev, B43_PHY_G_LO_CONTROL, backup[13]);
2847 if (phy->rev >= 2) {
2848 b43_phy_write(dev, 0x0812,
2849 b43_phy_read(dev, 0x0812) & 0xFFCF);
2850 b43_phy_write(dev, 0x0811,
2851 b43_phy_read(dev, 0x0811) & 0xFFCF);
2854 b43_radio_write16(dev, 0x007A, backup[0]);
2855 b43_radio_write16(dev, 0x0052, backup[1]);
2856 b43_radio_write16(dev, 0x0043, backup[2]);
2857 b43_write16(dev, 0x03E2, backup[7]);
2858 b43_write16(dev, 0x03E6, backup[8]);
2859 b43_write16(dev, B43_MMIO_CHANNEL_EXT, backup[9]);
2860 b43_phy_write(dev, 0x0015, backup[3]);
2861 b43_phy_write(dev, 0x005A, backup[4]);
2862 b43_phy_write(dev, 0x0059, backup[5]);
2863 b43_phy_write(dev, 0x0058, backup[6]);
2864 b43_synth_pu_workaround(dev, phy->channel);
2865 b43_phy_write(dev, 0x0802,
2866 b43_phy_read(dev, 0x0802) | (0x0001 | 0x0002));
2867 b43_set_original_gains(dev);
2868 b43_phy_write(dev, B43_PHY_G_CRS,
2869 b43_phy_read(dev, B43_PHY_G_CRS) | 0x8000);
2870 if (phy->rev >= 3) {
2871 b43_phy_write(dev, 0x0801, backup[14]);
2872 b43_phy_write(dev, 0x0060, backup[15]);
2873 b43_phy_write(dev, 0x0014, backup[16]);
2874 b43_phy_write(dev, 0x0478, backup[17]);
2876 b43_nrssi_mem_update(dev);
2877 b43_calc_nrssi_threshold(dev);
2884 void b43_calc_nrssi_threshold(struct b43_wldev *dev)
2886 struct b43_phy *phy = &dev->phy;
2892 switch (phy->type) {
2893 case B43_PHYTYPE_B:{
2894 if (phy->radio_ver != 0x2050)
2897 (dev->dev->bus->sprom.
2898 boardflags_lo & B43_BFL_RSSI))
2901 if (phy->radio_rev >= 6) {
2903 (phy->nrssi[1] - phy->nrssi[0]) * 32;
2904 threshold += 20 * (phy->nrssi[0] + 1);
2907 threshold = phy->nrssi[1] - 5;
2909 threshold = limit_value(threshold, 0, 0x3E);
2910 b43_phy_read(dev, 0x0020); /* dummy read */
2911 b43_phy_write(dev, 0x0020,
2912 (((u16) threshold) << 8) | 0x001C);
2914 if (phy->radio_rev >= 6) {
2915 b43_phy_write(dev, 0x0087, 0x0E0D);
2916 b43_phy_write(dev, 0x0086, 0x0C0B);
2917 b43_phy_write(dev, 0x0085, 0x0A09);
2918 b43_phy_write(dev, 0x0084, 0x0808);
2919 b43_phy_write(dev, 0x0083, 0x0808);
2920 b43_phy_write(dev, 0x0082, 0x0604);
2921 b43_phy_write(dev, 0x0081, 0x0302);
2922 b43_phy_write(dev, 0x0080, 0x0100);
2928 !(dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI)) {
2929 tmp16 = b43_nrssi_hw_read(dev, 0x20);
2933 b43_phy_write(dev, 0x048A,
2934 (b43_phy_read(dev, 0x048A)
2935 & 0xF000) | 0x09EB);
2937 b43_phy_write(dev, 0x048A,
2938 (b43_phy_read(dev, 0x048A)
2939 & 0xF000) | 0x0AED);
2942 if (phy->interfmode == B43_INTERFMODE_NONWLAN) {
2945 } else if (!phy->aci_wlan_automatic && phy->aci_enable) {
2953 a = a * (phy->nrssi[1] - phy->nrssi[0]);
2954 a += (phy->nrssi[0] << 6);
2960 a = limit_value(a, -31, 31);
2962 b = b * (phy->nrssi[1] - phy->nrssi[0]);
2963 b += (phy->nrssi[0] << 6);
2969 b = limit_value(b, -31, 31);
2971 tmp_u16 = b43_phy_read(dev, 0x048A) & 0xF000;
2972 tmp_u16 |= ((u32) b & 0x0000003F);
2973 tmp_u16 |= (((u32) a & 0x0000003F) << 6);
2974 b43_phy_write(dev, 0x048A, tmp_u16);
2982 /* Stack implementation to save/restore values from the
2983 * interference mitigation code.
2984 * It is save to restore values in random order.
2986 static void _stack_save(u32 * _stackptr, size_t * stackidx,
2987 u8 id, u16 offset, u16 value)
2989 u32 *stackptr = &(_stackptr[*stackidx]);
2991 B43_WARN_ON(offset & 0xF000);
2992 B43_WARN_ON(id & 0xF0);
2994 *stackptr |= ((u32) id) << 12;
2995 *stackptr |= ((u32) value) << 16;
2997 B43_WARN_ON(*stackidx >= B43_INTERFSTACK_SIZE);
3000 static u16 _stack_restore(u32 * stackptr, u8 id, u16 offset)
3004 B43_WARN_ON(offset & 0xF000);
3005 B43_WARN_ON(id & 0xF0);
3006 for (i = 0; i < B43_INTERFSTACK_SIZE; i++, stackptr++) {
3007 if ((*stackptr & 0x00000FFF) != offset)
3009 if (((*stackptr & 0x0000F000) >> 12) != id)
3011 return ((*stackptr & 0xFFFF0000) >> 16);
3018 #define phy_stacksave(offset) \
3020 _stack_save(stack, &stackidx, 0x1, (offset), \
3021 b43_phy_read(dev, (offset))); \
3023 #define phy_stackrestore(offset) \
3025 b43_phy_write(dev, (offset), \
3026 _stack_restore(stack, 0x1, \
3029 #define radio_stacksave(offset) \
3031 _stack_save(stack, &stackidx, 0x2, (offset), \
3032 b43_radio_read16(dev, (offset))); \
3034 #define radio_stackrestore(offset) \
3036 b43_radio_write16(dev, (offset), \
3037 _stack_restore(stack, 0x2, \
3040 #define ofdmtab_stacksave(table, offset) \
3042 _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
3043 b43_ofdmtab_read16(dev, (table), (offset))); \
3045 #define ofdmtab_stackrestore(table, offset) \
3047 b43_ofdmtab_write16(dev, (table), (offset), \
3048 _stack_restore(stack, 0x3, \
3049 (offset)|(table))); \
3053 b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
3055 struct b43_phy *phy = &dev->phy;
3057 size_t stackidx = 0;
3058 u32 *stack = phy->interfstack;
3061 case B43_INTERFMODE_NONWLAN:
3062 if (phy->rev != 1) {
3063 b43_phy_write(dev, 0x042B,
3064 b43_phy_read(dev, 0x042B) | 0x0800);
3065 b43_phy_write(dev, B43_PHY_G_CRS,
3067 B43_PHY_G_CRS) & ~0x4000);
3070 radio_stacksave(0x0078);
3071 tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
3072 flipped = flip_4bit(tmp);
3073 if (flipped < 10 && flipped >= 8)
3075 else if (flipped >= 10)
3077 flipped = flip_4bit(flipped);
3078 flipped = (flipped << 1) | 0x0020;
3079 b43_radio_write16(dev, 0x0078, flipped);
3081 b43_calc_nrssi_threshold(dev);
3083 phy_stacksave(0x0406);
3084 b43_phy_write(dev, 0x0406, 0x7E28);
3086 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) | 0x0800);
3087 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3089 B43_PHY_RADIO_BITFIELD) | 0x1000);
3091 phy_stacksave(0x04A0);
3092 b43_phy_write(dev, 0x04A0,
3093 (b43_phy_read(dev, 0x04A0) & 0xC0C0) | 0x0008);
3094 phy_stacksave(0x04A1);
3095 b43_phy_write(dev, 0x04A1,
3096 (b43_phy_read(dev, 0x04A1) & 0xC0C0) | 0x0605);
3097 phy_stacksave(0x04A2);
3098 b43_phy_write(dev, 0x04A2,
3099 (b43_phy_read(dev, 0x04A2) & 0xC0C0) | 0x0204);
3100 phy_stacksave(0x04A8);
3101 b43_phy_write(dev, 0x04A8,
3102 (b43_phy_read(dev, 0x04A8) & 0xC0C0) | 0x0803);
3103 phy_stacksave(0x04AB);
3104 b43_phy_write(dev, 0x04AB,
3105 (b43_phy_read(dev, 0x04AB) & 0xC0C0) | 0x0605);
3107 phy_stacksave(0x04A7);
3108 b43_phy_write(dev, 0x04A7, 0x0002);
3109 phy_stacksave(0x04A3);
3110 b43_phy_write(dev, 0x04A3, 0x287A);
3111 phy_stacksave(0x04A9);
3112 b43_phy_write(dev, 0x04A9, 0x2027);
3113 phy_stacksave(0x0493);
3114 b43_phy_write(dev, 0x0493, 0x32F5);
3115 phy_stacksave(0x04AA);
3116 b43_phy_write(dev, 0x04AA, 0x2027);
3117 phy_stacksave(0x04AC);
3118 b43_phy_write(dev, 0x04AC, 0x32F5);
3120 case B43_INTERFMODE_MANUALWLAN:
3121 if (b43_phy_read(dev, 0x0033) & 0x0800)
3124 phy->aci_enable = 1;
3126 phy_stacksave(B43_PHY_RADIO_BITFIELD);
3127 phy_stacksave(B43_PHY_G_CRS);
3129 phy_stacksave(0x0406);
3131 phy_stacksave(0x04C0);
3132 phy_stacksave(0x04C1);
3134 phy_stacksave(0x0033);
3135 phy_stacksave(0x04A7);
3136 phy_stacksave(0x04A3);
3137 phy_stacksave(0x04A9);
3138 phy_stacksave(0x04AA);
3139 phy_stacksave(0x04AC);
3140 phy_stacksave(0x0493);
3141 phy_stacksave(0x04A1);
3142 phy_stacksave(0x04A0);
3143 phy_stacksave(0x04A2);
3144 phy_stacksave(0x048A);
3145 phy_stacksave(0x04A8);
3146 phy_stacksave(0x04AB);
3147 if (phy->rev == 2) {
3148 phy_stacksave(0x04AD);
3149 phy_stacksave(0x04AE);
3150 } else if (phy->rev >= 3) {
3151 phy_stacksave(0x04AD);
3152 phy_stacksave(0x0415);
3153 phy_stacksave(0x0416);
3154 phy_stacksave(0x0417);
3155 ofdmtab_stacksave(0x1A00, 0x2);
3156 ofdmtab_stacksave(0x1A00, 0x3);
3158 phy_stacksave(0x042B);
3159 phy_stacksave(0x048C);
3161 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3162 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3164 b43_phy_write(dev, B43_PHY_G_CRS,
3165 (b43_phy_read(dev, B43_PHY_G_CRS)
3166 & 0xFFFC) | 0x0002);
3168 b43_phy_write(dev, 0x0033, 0x0800);
3169 b43_phy_write(dev, 0x04A3, 0x2027);
3170 b43_phy_write(dev, 0x04A9, 0x1CA8);
3171 b43_phy_write(dev, 0x0493, 0x287A);
3172 b43_phy_write(dev, 0x04AA, 0x1CA8);
3173 b43_phy_write(dev, 0x04AC, 0x287A);
3175 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3176 & 0xFFC0) | 0x001A);
3177 b43_phy_write(dev, 0x04A7, 0x000D);
3180 b43_phy_write(dev, 0x0406, 0xFF0D);
3181 } else if (phy->rev == 2) {
3182 b43_phy_write(dev, 0x04C0, 0xFFFF);
3183 b43_phy_write(dev, 0x04C1, 0x00A9);
3185 b43_phy_write(dev, 0x04C0, 0x00C1);
3186 b43_phy_write(dev, 0x04C1, 0x0059);
3189 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3190 & 0xC0FF) | 0x1800);
3191 b43_phy_write(dev, 0x04A1, (b43_phy_read(dev, 0x04A1)
3192 & 0xFFC0) | 0x0015);
3193 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3194 & 0xCFFF) | 0x1000);
3195 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3196 & 0xF0FF) | 0x0A00);
3197 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3198 & 0xCFFF) | 0x1000);
3199 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3200 & 0xF0FF) | 0x0800);
3201 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3202 & 0xFFCF) | 0x0010);
3203 b43_phy_write(dev, 0x04AB, (b43_phy_read(dev, 0x04AB)
3204 & 0xFFF0) | 0x0005);
3205 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3206 & 0xFFCF) | 0x0010);
3207 b43_phy_write(dev, 0x04A8, (b43_phy_read(dev, 0x04A8)
3208 & 0xFFF0) | 0x0006);
3209 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3210 & 0xF0FF) | 0x0800);
3211 b43_phy_write(dev, 0x04A0, (b43_phy_read(dev, 0x04A0)
3212 & 0xF0FF) | 0x0500);
3213 b43_phy_write(dev, 0x04A2, (b43_phy_read(dev, 0x04A2)
3214 & 0xFFF0) | 0x000B);
3216 if (phy->rev >= 3) {
3217 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3219 b43_phy_write(dev, 0x0415, (b43_phy_read(dev, 0x0415)
3220 & 0x8000) | 0x36D8);
3221 b43_phy_write(dev, 0x0416, (b43_phy_read(dev, 0x0416)
3222 & 0x8000) | 0x36D8);
3223 b43_phy_write(dev, 0x0417, (b43_phy_read(dev, 0x0417)
3224 & 0xFE00) | 0x016D);
3226 b43_phy_write(dev, 0x048A, b43_phy_read(dev, 0x048A)
3228 b43_phy_write(dev, 0x048A, (b43_phy_read(dev, 0x048A)
3229 & 0x9FFF) | 0x2000);
3230 b43_hf_write(dev, b43_hf_read(dev) | B43_HF_ACIW);
3232 if (phy->rev >= 2) {
3233 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B)
3236 b43_phy_write(dev, 0x048C, (b43_phy_read(dev, 0x048C)
3237 & 0xF0FF) | 0x0200);
3238 if (phy->rev == 2) {
3239 b43_phy_write(dev, 0x04AE, (b43_phy_read(dev, 0x04AE)
3240 & 0xFF00) | 0x007F);
3241 b43_phy_write(dev, 0x04AD, (b43_phy_read(dev, 0x04AD)
3242 & 0x00FF) | 0x1300);
3243 } else if (phy->rev >= 6) {
3244 b43_ofdmtab_write16(dev, 0x1A00, 0x3, 0x007F);
3245 b43_ofdmtab_write16(dev, 0x1A00, 0x2, 0x007F);
3246 b43_phy_write(dev, 0x04AD, b43_phy_read(dev, 0x04AD)
3249 b43_calc_nrssi_slope(dev);
3257 b43_radio_interference_mitigation_disable(struct b43_wldev *dev, int mode)
3259 struct b43_phy *phy = &dev->phy;
3260 u32 *stack = phy->interfstack;
3263 case B43_INTERFMODE_NONWLAN:
3264 if (phy->rev != 1) {
3265 b43_phy_write(dev, 0x042B,
3266 b43_phy_read(dev, 0x042B) & ~0x0800);
3267 b43_phy_write(dev, B43_PHY_G_CRS,
3269 B43_PHY_G_CRS) | 0x4000);
3272 radio_stackrestore(0x0078);
3273 b43_calc_nrssi_threshold(dev);
3274 phy_stackrestore(0x0406);
3275 b43_phy_write(dev, 0x042B, b43_phy_read(dev, 0x042B) & ~0x0800);
3276 if (!dev->bad_frames_preempt) {
3277 b43_phy_write(dev, B43_PHY_RADIO_BITFIELD,
3278 b43_phy_read(dev, B43_PHY_RADIO_BITFIELD)
3281 b43_phy_write(dev, B43_PHY_G_CRS,
3282 b43_phy_read(dev, B43_PHY_G_CRS) | 0x4000);
3283 phy_stackrestore(0x04A0);
3284 phy_stackrestore(0x04A1);
3285 phy_stackrestore(0x04A2);
3286 phy_stackrestore(0x04A8);
3287 phy_stackrestore(0x04AB);
3288 phy_stackrestore(0x04A7);
3289 phy_stackrestore(0x04A3);
3290 phy_stackrestore(0x04A9);
3291 phy_stackrestore(0x0493);
3292 phy_stackrestore(0x04AA);
3293 phy_stackrestore(0x04AC);
3295 case B43_INTERFMODE_MANUALWLAN:
3296 if (!(b43_phy_read(dev, 0x0033) & 0x0800))
3299 phy->aci_enable = 0;
3301 phy_stackrestore(B43_PHY_RADIO_BITFIELD);
3302 phy_stackrestore(B43_PHY_G_CRS);
3303 phy_stackrestore(0x0033);
3304 phy_stackrestore(0x04A3);
3305 phy_stackrestore(0x04A9);
3306 phy_stackrestore(0x0493);
3307 phy_stackrestore(0x04AA);
3308 phy_stackrestore(0x04AC);
3309 phy_stackrestore(0x04A0);
3310 phy_stackrestore(0x04A7);
3311 if (phy->rev >= 2) {
3312 phy_stackrestore(0x04C0);
3313 phy_stackrestore(0x04C1);
3315 phy_stackrestore(0x0406);
3316 phy_stackrestore(0x04A1);
3317 phy_stackrestore(0x04AB);
3318 phy_stackrestore(0x04A8);
3319 if (phy->rev == 2) {
3320 phy_stackrestore(0x04AD);
3321 phy_stackrestore(0x04AE);
3322 } else if (phy->rev >= 3) {
3323 phy_stackrestore(0x04AD);
3324 phy_stackrestore(0x0415);
3325 phy_stackrestore(0x0416);
3326 phy_stackrestore(0x0417);
3327 ofdmtab_stackrestore(0x1A00, 0x2);
3328 ofdmtab_stackrestore(0x1A00, 0x3);
3330 phy_stackrestore(0x04A2);
3331 phy_stackrestore(0x048A);
3332 phy_stackrestore(0x042B);
3333 phy_stackrestore(0x048C);
3334 b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_ACIW);
3335 b43_calc_nrssi_slope(dev);
3342 #undef phy_stacksave
3343 #undef phy_stackrestore
3344 #undef radio_stacksave
3345 #undef radio_stackrestore
3346 #undef ofdmtab_stacksave
3347 #undef ofdmtab_stackrestore
3349 int b43_radio_set_interference_mitigation(struct b43_wldev *dev, int mode)
3351 struct b43_phy *phy = &dev->phy;
3354 if ((phy->type != B43_PHYTYPE_G) || (phy->rev == 0) || (!phy->gmode))
3357 phy->aci_wlan_automatic = 0;
3359 case B43_INTERFMODE_AUTOWLAN:
3360 phy->aci_wlan_automatic = 1;
3361 if (phy->aci_enable)
3362 mode = B43_INTERFMODE_MANUALWLAN;
3364 mode = B43_INTERFMODE_NONE;
3366 case B43_INTERFMODE_NONE:
3367 case B43_INTERFMODE_NONWLAN:
3368 case B43_INTERFMODE_MANUALWLAN:
3374 currentmode = phy->interfmode;
3375 if (currentmode == mode)
3377 if (currentmode != B43_INTERFMODE_NONE)
3378 b43_radio_interference_mitigation_disable(dev, currentmode);
3380 if (mode == B43_INTERFMODE_NONE) {
3381 phy->aci_enable = 0;
3382 phy->aci_hw_rssi = 0;
3384 b43_radio_interference_mitigation_enable(dev, mode);
3385 phy->interfmode = mode;
3390 static u16 b43_radio_core_calibration_value(struct b43_wldev *dev)
3392 u16 reg, index, ret;
3394 static const u8 rcc_table[] = {
3395 0x02, 0x03, 0x01, 0x0F,
3396 0x06, 0x07, 0x05, 0x0F,
3397 0x0A, 0x0B, 0x09, 0x0F,
3398 0x0E, 0x0F, 0x0D, 0x0F,
3401 reg = b43_radio_read16(dev, 0x60);
3402 index = (reg & 0x001E) >> 1;
3403 ret = rcc_table[index] << 1;
3404 ret |= (reg & 0x0001);
3410 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
3411 static u16 radio2050_rfover_val(struct b43_wldev *dev,
3412 u16 phy_register, unsigned int lpd)
3414 struct b43_phy *phy = &dev->phy;
3415 struct ssb_sprom *sprom = &(dev->dev->bus->sprom);
3420 if (has_loopback_gain(phy)) {
3421 int max_lb_gain = phy->max_lb_gain;
3425 if (phy->radio_rev == 8)
3426 max_lb_gain += 0x3E;
3428 max_lb_gain += 0x26;
3429 if (max_lb_gain >= 0x46) {
3431 max_lb_gain -= 0x46;
3432 } else if (max_lb_gain >= 0x3A) {
3434 max_lb_gain -= 0x3A;
3435 } else if (max_lb_gain >= 0x2E) {
3437 max_lb_gain -= 0x2E;
3440 max_lb_gain -= 0x10;
3443 for (i = 0; i < 16; i++) {
3444 max_lb_gain -= (i * 6);
3445 if (max_lb_gain < 6)
3449 if ((phy->rev < 7) ||
3450 !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
3451 if (phy_register == B43_PHY_RFOVER) {
3453 } else if (phy_register == B43_PHY_RFOVERVAL) {
3460 return (0x0092 | extlna);
3462 return (0x0093 | extlna);
3468 if (phy_register == B43_PHY_RFOVER) {
3470 } else if (phy_register == B43_PHY_RFOVERVAL) {
3478 return (0x8092 | extlna);
3480 return (0x2092 | extlna);
3482 return (0x2093 | extlna);
3489 if ((phy->rev < 7) ||
3490 !(sprom->boardflags_lo & B43_BFL_EXTLNA)) {
3491 if (phy_register == B43_PHY_RFOVER) {
3493 } else if (phy_register == B43_PHY_RFOVERVAL) {
3508 if (phy_register == B43_PHY_RFOVER) {
3510 } else if (phy_register == B43_PHY_RFOVERVAL) {
3529 struct init2050_saved_values {
3530 /* Core registers */
3534 /* Radio registers */
3547 u16 phy_analogoverval;
3555 u16 b43_radio_init2050(struct b43_wldev *dev)
3557 struct b43_phy *phy = &dev->phy;
3558 struct init2050_saved_values sav;
3563 u32 tmp1 = 0, tmp2 = 0;
3565 memset(&sav, 0, sizeof(sav)); /* get rid of "may be used uninitialized..." */
3567 sav.radio_43 = b43_radio_read16(dev, 0x43);
3568 sav.radio_51 = b43_radio_read16(dev, 0x51);
3569 sav.radio_52 = b43_radio_read16(dev, 0x52);
3570 sav.phy_pgactl = b43_phy_read(dev, B43_PHY_PGACTL);
3571 sav.phy_cck_5A = b43_phy_read(dev, B43_PHY_CCK(0x5A));
3572 sav.phy_cck_59 = b43_phy_read(dev, B43_PHY_CCK(0x59));
3573 sav.phy_cck_58 = b43_phy_read(dev, B43_PHY_CCK(0x58));
3575 if (phy->type == B43_PHYTYPE_B) {
3576 sav.phy_cck_30 = b43_phy_read(dev, B43_PHY_CCK(0x30));
3577 sav.reg_3EC = b43_read16(dev, 0x3EC);
3579 b43_phy_write(dev, B43_PHY_CCK(0x30), 0xFF);
3580 b43_write16(dev, 0x3EC, 0x3F3F);
3581 } else if (phy->gmode || phy->rev >= 2) {
3582 sav.phy_rfover = b43_phy_read(dev, B43_PHY_RFOVER);
3583 sav.phy_rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
3584 sav.phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
3585 sav.phy_analogoverval =
3586 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL);
3587 sav.phy_crs0 = b43_phy_read(dev, B43_PHY_CRS0);
3588 sav.phy_classctl = b43_phy_read(dev, B43_PHY_CLASSCTL);
3590 b43_phy_write(dev, B43_PHY_ANALOGOVER,
3591 b43_phy_read(dev, B43_PHY_ANALOGOVER)
3593 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3594 b43_phy_read(dev, B43_PHY_ANALOGOVERVAL)
3596 b43_phy_write(dev, B43_PHY_CRS0, b43_phy_read(dev, B43_PHY_CRS0)
3598 b43_phy_write(dev, B43_PHY_CLASSCTL,
3599 b43_phy_read(dev, B43_PHY_CLASSCTL)
3601 if (has_loopback_gain(phy)) {
3602 sav.phy_lo_mask = b43_phy_read(dev, B43_PHY_LO_MASK);
3603 sav.phy_lo_ctl = b43_phy_read(dev, B43_PHY_LO_CTL);
3606 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC020);
3608 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8020);
3609 b43_phy_write(dev, B43_PHY_LO_CTL, 0);
3612 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3613 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3615 b43_phy_write(dev, B43_PHY_RFOVER,
3616 radio2050_rfover_val(dev, B43_PHY_RFOVER, 0));
3618 b43_write16(dev, 0x3E2, b43_read16(dev, 0x3E2) | 0x8000);
3620 sav.phy_syncctl = b43_phy_read(dev, B43_PHY_SYNCCTL);
3621 b43_phy_write(dev, B43_PHY_SYNCCTL, b43_phy_read(dev, B43_PHY_SYNCCTL)
3623 sav.reg_3E6 = b43_read16(dev, 0x3E6);
3624 sav.reg_3F4 = b43_read16(dev, 0x3F4);
3626 if (phy->analog == 0) {
3627 b43_write16(dev, 0x03E6, 0x0122);
3629 if (phy->analog >= 2) {
3630 b43_phy_write(dev, B43_PHY_CCK(0x03),
3631 (b43_phy_read(dev, B43_PHY_CCK(0x03))
3634 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3635 (b43_read16(dev, B43_MMIO_CHANNEL_EXT) | 0x2000));
3638 rcc = b43_radio_core_calibration_value(dev);
3640 if (phy->type == B43_PHYTYPE_B)
3641 b43_radio_write16(dev, 0x78, 0x26);
3642 if (phy->gmode || phy->rev >= 2) {
3643 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3644 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3647 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFAF);
3648 b43_phy_write(dev, B43_PHY_CCK(0x2B), 0x1403);
3649 if (phy->gmode || phy->rev >= 2) {
3650 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3651 radio2050_rfover_val(dev, B43_PHY_RFOVERVAL,
3654 b43_phy_write(dev, B43_PHY_PGACTL, 0xBFA0);
3655 b43_radio_write16(dev, 0x51, b43_radio_read16(dev, 0x51)
3657 if (phy->radio_rev == 8) {
3658 b43_radio_write16(dev, 0x43, 0x1F);
3660 b43_radio_write16(dev, 0x52, 0);
3661 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43)
3662 & 0xFFF0) | 0x0009);
3664 b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
3666 for (i = 0; i < 16; i++) {
3667 b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0480);
3668 b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
3669 b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
3670 if (phy->gmode || phy->rev >= 2) {
3671 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3672 radio2050_rfover_val(dev,
3676 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3678 if (phy->gmode || phy->rev >= 2) {
3679 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3680 radio2050_rfover_val(dev,
3684 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3686 if (phy->gmode || phy->rev >= 2) {
3687 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3688 radio2050_rfover_val(dev,
3692 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3694 tmp1 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3695 b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
3696 if (phy->gmode || phy->rev >= 2) {
3697 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3698 radio2050_rfover_val(dev,
3702 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3706 b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
3710 for (i = 0; i < 16; i++) {
3711 radio78 = ((flip_4bit(i) << 1) | 0x20);
3712 b43_radio_write16(dev, 0x78, radio78);
3714 for (j = 0; j < 16; j++) {
3715 b43_phy_write(dev, B43_PHY_CCK(0x5A), 0x0D80);
3716 b43_phy_write(dev, B43_PHY_CCK(0x59), 0xC810);
3717 b43_phy_write(dev, B43_PHY_CCK(0x58), 0x000D);
3718 if (phy->gmode || phy->rev >= 2) {
3719 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3720 radio2050_rfover_val(dev,
3725 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3727 if (phy->gmode || phy->rev >= 2) {
3728 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3729 radio2050_rfover_val(dev,
3734 b43_phy_write(dev, B43_PHY_PGACTL, 0xEFB0);
3736 if (phy->gmode || phy->rev >= 2) {
3737 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3738 radio2050_rfover_val(dev,
3743 b43_phy_write(dev, B43_PHY_PGACTL, 0xFFF0);
3745 tmp2 += b43_phy_read(dev, B43_PHY_LO_LEAKAGE);
3746 b43_phy_write(dev, B43_PHY_CCK(0x58), 0);
3747 if (phy->gmode || phy->rev >= 2) {
3748 b43_phy_write(dev, B43_PHY_RFOVERVAL,
3749 radio2050_rfover_val(dev,
3754 b43_phy_write(dev, B43_PHY_PGACTL, 0xAFB0);
3762 /* Restore the registers */
3763 b43_phy_write(dev, B43_PHY_PGACTL, sav.phy_pgactl);
3764 b43_radio_write16(dev, 0x51, sav.radio_51);
3765 b43_radio_write16(dev, 0x52, sav.radio_52);
3766 b43_radio_write16(dev, 0x43, sav.radio_43);
3767 b43_phy_write(dev, B43_PHY_CCK(0x5A), sav.phy_cck_5A);
3768 b43_phy_write(dev, B43_PHY_CCK(0x59), sav.phy_cck_59);
3769 b43_phy_write(dev, B43_PHY_CCK(0x58), sav.phy_cck_58);
3770 b43_write16(dev, 0x3E6, sav.reg_3E6);
3771 if (phy->analog != 0)
3772 b43_write16(dev, 0x3F4, sav.reg_3F4);
3773 b43_phy_write(dev, B43_PHY_SYNCCTL, sav.phy_syncctl);
3774 b43_synth_pu_workaround(dev, phy->channel);
3775 if (phy->type == B43_PHYTYPE_B) {
3776 b43_phy_write(dev, B43_PHY_CCK(0x30), sav.phy_cck_30);
3777 b43_write16(dev, 0x3EC, sav.reg_3EC);
3778 } else if (phy->gmode) {
3779 b43_write16(dev, B43_MMIO_PHY_RADIO,
3780 b43_read16(dev, B43_MMIO_PHY_RADIO)
3782 b43_phy_write(dev, B43_PHY_RFOVER, sav.phy_rfover);
3783 b43_phy_write(dev, B43_PHY_RFOVERVAL, sav.phy_rfoverval);
3784 b43_phy_write(dev, B43_PHY_ANALOGOVER, sav.phy_analogover);
3785 b43_phy_write(dev, B43_PHY_ANALOGOVERVAL,
3786 sav.phy_analogoverval);
3787 b43_phy_write(dev, B43_PHY_CRS0, sav.phy_crs0);
3788 b43_phy_write(dev, B43_PHY_CLASSCTL, sav.phy_classctl);
3789 if (has_loopback_gain(phy)) {
3790 b43_phy_write(dev, B43_PHY_LO_MASK, sav.phy_lo_mask);
3791 b43_phy_write(dev, B43_PHY_LO_CTL, sav.phy_lo_ctl);
3802 void b43_radio_init2060(struct b43_wldev *dev)
3806 b43_radio_write16(dev, 0x0004, 0x00C0);
3807 b43_radio_write16(dev, 0x0005, 0x0008);
3808 b43_radio_write16(dev, 0x0009, 0x0040);
3809 b43_radio_write16(dev, 0x0005, 0x00AA);
3810 b43_radio_write16(dev, 0x0032, 0x008F);
3811 b43_radio_write16(dev, 0x0006, 0x008F);
3812 b43_radio_write16(dev, 0x0034, 0x008F);
3813 b43_radio_write16(dev, 0x002C, 0x0007);
3814 b43_radio_write16(dev, 0x0082, 0x0080);
3815 b43_radio_write16(dev, 0x0080, 0x0000);
3816 b43_radio_write16(dev, 0x003F, 0x00DA);
3817 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
3818 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0010);
3819 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
3820 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0020);
3821 msleep(1); /* delay 400usec */
3823 b43_radio_write16(dev, 0x0081,
3824 (b43_radio_read16(dev, 0x0081) & ~0x0020) | 0x0010);
3825 msleep(1); /* delay 400usec */
3827 b43_radio_write16(dev, 0x0005,
3828 (b43_radio_read16(dev, 0x0005) & ~0x0008) | 0x0008);
3829 b43_radio_write16(dev, 0x0085, b43_radio_read16(dev, 0x0085) & ~0x0010);
3830 b43_radio_write16(dev, 0x0005, b43_radio_read16(dev, 0x0005) & ~0x0008);
3831 b43_radio_write16(dev, 0x0081, b43_radio_read16(dev, 0x0081) & ~0x0040);
3832 b43_radio_write16(dev, 0x0081,
3833 (b43_radio_read16(dev, 0x0081) & ~0x0040) | 0x0040);
3834 b43_radio_write16(dev, 0x0005,
3835 (b43_radio_read16(dev, 0x0081) & ~0x0008) | 0x0008);
3836 b43_phy_write(dev, 0x0063, 0xDDC6);
3837 b43_phy_write(dev, 0x0069, 0x07BE);
3838 b43_phy_write(dev, 0x006A, 0x0000);
3840 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_A, 0);
3846 static inline u16 freq_r3A_value(u16 frequency)
3850 if (frequency < 5091)
3852 else if (frequency < 5321)
3854 else if (frequency < 5806)
3862 void b43_radio_set_tx_iq(struct b43_wldev *dev)
3864 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
3865 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
3866 u16 tmp = b43_radio_read16(dev, 0x001E);
3869 for (i = 0; i < 5; i++) {
3870 for (j = 0; j < 5; j++) {
3871 if (tmp == (data_high[i] << 4 | data_low[j])) {
3872 b43_phy_write(dev, 0x0069,
3873 (i - j) << 8 | 0x00C0);
3880 int b43_radio_selectchannel(struct b43_wldev *dev,
3881 u8 channel, int synthetic_pu_workaround)
3883 struct b43_phy *phy = &dev->phy;
3886 u16 channelcookie, savedcookie;
3889 if (channel == 0xFF) {
3890 switch (phy->type) {
3892 channel = B43_DEFAULT_CHANNEL_A;
3896 channel = B43_DEFAULT_CHANNEL_BG;
3899 //FIXME check if we are on 2.4GHz or 5GHz and set a default channel.
3907 /* First we set the channel radio code to prevent the
3908 * firmware from sending ghost packets.
3910 channelcookie = channel;
3911 if (0 /*FIXME on 5Ghz */)
3912 channelcookie |= 0x100;
3913 //FIXME set 40Mhz flag if required
3914 savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN);
3915 b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
3917 switch (phy->type) {
3919 if (channel > 200) {
3923 freq = channel2freq_a(channel);
3925 r8 = b43_radio_read16(dev, 0x0008);
3926 b43_write16(dev, 0x03F0, freq);
3927 b43_radio_write16(dev, 0x0008, r8);
3929 //TODO: write max channel TX power? to Radio 0x2D
3930 tmp = b43_radio_read16(dev, 0x002E);
3932 //TODO: OR tmp with the Power out estimation for this channel?
3933 b43_radio_write16(dev, 0x002E, tmp);
3935 if (freq >= 4920 && freq <= 5500) {
3937 * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
3938 * = (freq * 0.025862069
3940 r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
3942 b43_radio_write16(dev, 0x0007, (r8 << 4) | r8);
3943 b43_radio_write16(dev, 0x0020, (r8 << 4) | r8);
3944 b43_radio_write16(dev, 0x0021, (r8 << 4) | r8);
3945 b43_radio_write16(dev, 0x0022, (b43_radio_read16(dev, 0x0022)
3946 & 0x000F) | (r8 << 4));
3947 b43_radio_write16(dev, 0x002A, (r8 << 4));
3948 b43_radio_write16(dev, 0x002B, (r8 << 4));
3949 b43_radio_write16(dev, 0x0008, (b43_radio_read16(dev, 0x0008)
3950 & 0x00F0) | (r8 << 4));
3951 b43_radio_write16(dev, 0x0029, (b43_radio_read16(dev, 0x0029)
3952 & 0xFF0F) | 0x00B0);
3953 b43_radio_write16(dev, 0x0035, 0x00AA);
3954 b43_radio_write16(dev, 0x0036, 0x0085);
3955 b43_radio_write16(dev, 0x003A, (b43_radio_read16(dev, 0x003A)
3957 freq_r3A_value(freq));
3958 b43_radio_write16(dev, 0x003D,
3959 b43_radio_read16(dev, 0x003D) & 0x00FF);
3960 b43_radio_write16(dev, 0x0081, (b43_radio_read16(dev, 0x0081)
3961 & 0xFF7F) | 0x0080);
3962 b43_radio_write16(dev, 0x0035,
3963 b43_radio_read16(dev, 0x0035) & 0xFFEF);
3964 b43_radio_write16(dev, 0x0035, (b43_radio_read16(dev, 0x0035)
3965 & 0xFFEF) | 0x0010);
3966 b43_radio_set_tx_iq(dev);
3967 //TODO: TSSI2dbm workaround
3968 b43_phy_xmitpower(dev); //FIXME correct?
3971 if ((channel < 1) || (channel > 14)) {
3976 if (synthetic_pu_workaround)
3977 b43_synth_pu_workaround(dev, channel);
3979 b43_write16(dev, B43_MMIO_CHANNEL, channel2freq_bg(channel));
3981 if (channel == 14) {
3982 if (dev->dev->bus->sprom.country_code ==
3983 SSB_SPROM1CCODE_JAPAN)
3985 b43_hf_read(dev) & ~B43_HF_ACPR);
3988 b43_hf_read(dev) | B43_HF_ACPR);
3989 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3990 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3993 b43_write16(dev, B43_MMIO_CHANNEL_EXT,
3994 b43_read16(dev, B43_MMIO_CHANNEL_EXT)
3999 err = b43_nphy_selectchannel(dev, channel);
4007 phy->channel = channel;
4008 /* Wait for the radio to tune to the channel and stabilize. */
4012 b43_shm_write16(dev, B43_SHM_SHARED,
4013 B43_SHM_SH_CHAN, savedcookie);
4018 void b43_radio_turn_on(struct b43_wldev *dev)
4020 struct b43_phy *phy = &dev->phy;
4029 switch (phy->type) {
4031 b43_radio_write16(dev, 0x0004, 0x00C0);
4032 b43_radio_write16(dev, 0x0005, 0x0008);
4033 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) & 0xFFF7);
4034 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) & 0xFFF7);
4035 b43_radio_init2060(dev);
4039 b43_phy_write(dev, 0x0015, 0x8000);
4040 b43_phy_write(dev, 0x0015, 0xCC00);
4041 b43_phy_write(dev, 0x0015, (phy->gmode ? 0x00C0 : 0x0000));
4042 if (phy->radio_off_context.valid) {
4043 /* Restore the RFover values. */
4044 b43_phy_write(dev, B43_PHY_RFOVER,
4045 phy->radio_off_context.rfover);
4046 b43_phy_write(dev, B43_PHY_RFOVERVAL,
4047 phy->radio_off_context.rfoverval);
4048 phy->radio_off_context.valid = 0;
4050 channel = phy->channel;
4051 err = b43_radio_selectchannel(dev, B43_DEFAULT_CHANNEL_BG, 1);
4052 err |= b43_radio_selectchannel(dev, channel, 0);
4056 b43_nphy_radio_turn_on(dev);
4064 void b43_radio_turn_off(struct b43_wldev *dev, bool force)
4066 struct b43_phy *phy = &dev->phy;
4068 if (!phy->radio_on && !force)
4071 switch (phy->type) {
4073 b43_nphy_radio_turn_off(dev);
4076 b43_radio_write16(dev, 0x0004, 0x00FF);
4077 b43_radio_write16(dev, 0x0005, 0x00FB);
4078 b43_phy_write(dev, 0x0010, b43_phy_read(dev, 0x0010) | 0x0008);
4079 b43_phy_write(dev, 0x0011, b43_phy_read(dev, 0x0011) | 0x0008);
4081 case B43_PHYTYPE_G: {
4082 u16 rfover, rfoverval;
4084 rfover = b43_phy_read(dev, B43_PHY_RFOVER);
4085 rfoverval = b43_phy_read(dev, B43_PHY_RFOVERVAL);
4087 phy->radio_off_context.rfover = rfover;
4088 phy->radio_off_context.rfoverval = rfoverval;
4089 phy->radio_off_context.valid = 1;
4091 b43_phy_write(dev, B43_PHY_RFOVER, rfover | 0x008C);
4092 b43_phy_write(dev, B43_PHY_RFOVERVAL, rfoverval & 0xFF73);