3 Broadcom BCM43xx wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
31 #include <linux/delay.h>
32 #include <linux/pci.h>
33 #include <linux/types.h>
36 #include "bcm43xx_phy.h"
37 #include "bcm43xx_main.h"
38 #include "bcm43xx_radio.h"
39 #include "bcm43xx_ilt.h"
40 #include "bcm43xx_power.h"
43 static const s8 bcm43xx_tssi2dbm_b_table[] = {
44 0x4D, 0x4C, 0x4B, 0x4A,
45 0x4A, 0x49, 0x48, 0x47,
46 0x47, 0x46, 0x45, 0x45,
47 0x44, 0x43, 0x42, 0x42,
48 0x41, 0x40, 0x3F, 0x3E,
49 0x3D, 0x3C, 0x3B, 0x3A,
50 0x39, 0x38, 0x37, 0x36,
51 0x35, 0x34, 0x32, 0x31,
52 0x30, 0x2F, 0x2D, 0x2C,
53 0x2B, 0x29, 0x28, 0x26,
54 0x25, 0x23, 0x21, 0x1F,
55 0x1D, 0x1A, 0x17, 0x14,
56 0x10, 0x0C, 0x06, 0x00,
62 static const s8 bcm43xx_tssi2dbm_g_table[] = {
81 static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
85 void bcm43xx_voluntary_preempt(void)
87 assert(!in_atomic() && !in_irq() &&
88 !in_interrupt() && !irqs_disabled());
89 #ifndef CONFIG_PREEMPT
91 #endif /* CONFIG_PREEMPT */
94 void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
96 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
98 assert(irqs_disabled());
99 if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
103 if (bcm->current_core->rev < 3) {
104 bcm43xx_mac_suspend(bcm);
105 spin_lock(&phy->lock);
107 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
108 bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
113 void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
115 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
117 assert(irqs_disabled());
118 if (bcm->current_core->rev < 3) {
119 if (phy->is_locked) {
120 spin_unlock(&phy->lock);
121 bcm43xx_mac_enable(bcm);
124 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
125 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
130 u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
132 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
133 return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
136 void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
138 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
140 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
143 void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
145 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
147 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
150 if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
151 bcm43xx_wireless_core_reset(bcm, 0);
152 bcm43xx_phy_initg(bcm);
153 bcm43xx_wireless_core_reset(bcm, 1);
159 * http://bcm-specs.sipsolutions.net/SetPHY
161 int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
163 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
166 if (bcm->current_core->rev < 5)
169 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
171 if (!(flags & 0x00010000))
173 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
174 flags |= (0x800 << 18);
175 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
177 if (!(flags & 0x00020000))
179 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
180 flags &= ~(0x800 << 18);
181 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
184 phy->connected = connect;
186 dprintk(KERN_INFO PFX "PHY connected\n");
188 dprintk(KERN_INFO PFX "PHY disconnected\n");
193 /* intialize B PHY power control
194 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
196 static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
198 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
199 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
200 u16 saved_batt = 0, saved_ratt = 0, saved_txctl1 = 0;
201 int must_reset_txpower = 0;
203 assert(phy->type != BCM43xx_PHYTYPE_A);
204 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
205 (bcm->board_type == 0x0416))
208 bcm43xx_phy_write(bcm, 0x0028, 0x8018);
209 bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
211 if (phy->type == BCM43xx_PHYTYPE_G) {
214 bcm43xx_phy_write(bcm, 0x047A, 0xC111);
216 if (phy->savedpctlreg != 0xFFFF)
219 if (phy->type == BCM43xx_PHYTYPE_B &&
221 radio->version == 0x2050) {
222 bcm43xx_radio_write16(bcm, 0x0076,
223 bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
225 saved_batt = radio->baseband_atten;
226 saved_ratt = radio->radio_atten;
227 saved_txctl1 = radio->txctl1;
228 if ((radio->revision >= 6) && (radio->revision <= 8)
229 && /*FIXME: incomplete specs for 5 < revision < 9 */ 0)
230 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 0x1F, 0);
232 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
233 must_reset_txpower = 1;
235 bcm43xx_dummy_transmission(bcm);
237 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
239 if (must_reset_txpower)
240 bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
242 bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
243 bcm43xx_radio_clear_tssi(bcm);
246 static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
248 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
254 bcm43xx_ilt_write(bcm, offset, 0x00FE);
255 bcm43xx_ilt_write(bcm, offset + 1, 0x000D);
256 bcm43xx_ilt_write(bcm, offset + 2, 0x0013);
257 bcm43xx_ilt_write(bcm, offset + 3, 0x0019);
260 bcm43xx_ilt_write(bcm, 0x1800, 0x2710);
261 bcm43xx_ilt_write(bcm, 0x1801, 0x9B83);
262 bcm43xx_ilt_write(bcm, 0x1802, 0x9B83);
263 bcm43xx_ilt_write(bcm, 0x1803, 0x0F8D);
264 bcm43xx_phy_write(bcm, 0x0455, 0x0004);
267 bcm43xx_phy_write(bcm, 0x04A5, (bcm43xx_phy_read(bcm, 0x04A5) & 0x00FF) | 0x5700);
268 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xFF80) | 0x000F);
269 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xC07F) | 0x2B80);
270 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xF0FF) | 0x0300);
272 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
274 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xFFF0) | 0x0008);
275 bcm43xx_phy_write(bcm, 0x04A1, (bcm43xx_phy_read(bcm, 0x04A1) & 0xF0FF) | 0x0600);
276 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xF0FF) | 0x0700);
277 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xF0FF) | 0x0100);
280 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
282 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xFF00) | 0x001C);
283 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xC0FF) | 0x0200);
284 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0xFF00) | 0x001C);
285 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xFF00) | 0x0020);
286 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xC0FF) | 0x0200);
287 bcm43xx_phy_write(bcm, 0x0482, (bcm43xx_phy_read(bcm, 0x0482) & 0xFF00) | 0x002E);
288 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0x00FF) | 0x1A00);
289 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0xFF00) | 0x0028);
290 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0x00FF) | 0x2C00);
293 bcm43xx_phy_write(bcm, 0x0430, 0x092B);
294 bcm43xx_phy_write(bcm, 0x041B, (bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1) | 0x0002);
296 bcm43xx_phy_write(bcm, 0x041B, bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1);
297 bcm43xx_phy_write(bcm, 0x041F, 0x287A);
298 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0xFFF0) | 0x0004);
302 bcm43xx_phy_write(bcm, 0x0422, 0x287A);
303 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0x0FFF) | 0x3000);
306 bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
307 bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
310 bcm43xx_phy_write(bcm, 0x04AB, (bcm43xx_phy_read(bcm, 0x04AB) & 0xF0FF) | 0x0600);
311 bcm43xx_phy_write(bcm, 0x048B, 0x005E);
312 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xFF00) | 0x001E);
313 bcm43xx_phy_write(bcm, 0x048D, 0x0002);
316 bcm43xx_ilt_write(bcm, offset + 0x0800, 0);
317 bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
318 bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
319 bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
322 bcm43xx_phy_write(bcm, 0x0426, (bcm43xx_phy_read(bcm, 0x0426)
324 bcm43xx_phy_write(bcm, 0x0426, (bcm43xx_phy_read(bcm, 0x0426)
329 static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
331 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
334 assert(phy->type == BCM43xx_PHYTYPE_G);
336 bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
337 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
338 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
339 bcm43xx_phy_write(bcm, 0x042C, 0x005A);
340 bcm43xx_phy_write(bcm, 0x0427, 0x001A);
342 for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
343 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
344 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
345 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
346 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
347 bcm43xx_ilt_write32(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
349 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
350 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
353 bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
354 bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
355 } else if (phy->rev > 2) {
356 bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
357 bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
358 bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
360 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
362 for (i = 0; i < 64; i++)
363 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
364 for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
365 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
369 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
370 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
371 else if ((phy->rev >= 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
372 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
373 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
375 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
376 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
379 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
380 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
381 else if ((phy->rev > 2) && (phy->rev <= 8))
382 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
383 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
386 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
387 bcm43xx_ilt_write32(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
388 for (i = 0; i < 4; i++) {
389 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
390 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
391 bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
392 bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
394 bcm43xx_phy_agcsetup(bcm);
396 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
397 (bcm->board_type == 0x0416) &&
398 (bcm->board_revision == 0x0017))
401 bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
402 bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
404 for (i = 0; i <= 0x2F; i++)
405 bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
406 bcm43xx_phy_agcsetup(bcm);
407 bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
408 bcm43xx_phy_write(bcm, 0x0403, 0x1000);
409 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
410 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
412 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
413 (bcm->board_type == 0x0416) &&
414 (bcm->board_revision == 0x0017))
417 bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
418 bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
422 /* Initialize the noisescaletable for APHY */
423 static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
425 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
428 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
429 for (i = 0; i < 12; i++) {
431 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
433 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
436 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
438 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
439 for (i = 0; i < 11; i++) {
441 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
443 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
446 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
448 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
451 static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
453 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
456 assert(phy->type == BCM43xx_PHYTYPE_A);
459 bcm43xx_phy_write(bcm, 0x008E, 0x3800);
460 bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
461 bcm43xx_phy_write(bcm, 0x0036, 0x0400);
463 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
465 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
466 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
467 bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
468 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
470 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
471 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
472 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
473 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
475 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
476 bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
477 bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
479 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
480 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
481 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
482 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
483 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
485 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
486 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
487 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
488 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
489 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
490 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
491 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
493 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
494 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
495 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
497 for (i = 0; i < 16; i++)
498 bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
500 bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
501 bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
502 bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
503 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
505 for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
506 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
507 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
508 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
509 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
510 bcm43xx_ilt_write32(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
511 bcm43xx_phy_init_noisescaletbl(bcm);
512 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
513 bcm43xx_ilt_write32(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
516 for (i = 0; i < 64; i++)
517 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
519 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
521 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
522 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
523 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
525 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
526 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
527 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
528 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
529 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
531 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
532 for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
533 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
534 bcm43xx_phy_init_noisescaletbl(bcm);
535 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
536 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
538 bcm43xx_phy_write(bcm, 0x0003, 0x1808);
540 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
541 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
542 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
543 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
544 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
546 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
547 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
548 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
549 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
550 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
551 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
552 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
554 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
555 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
556 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
558 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
559 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
566 /* Initialize APHY. This is also called for the GPHY in some cases. */
567 static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
569 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
570 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
573 if (phy->type == BCM43xx_PHYTYPE_A) {
574 bcm43xx_phy_setupa(bcm);
576 bcm43xx_phy_setupg(bcm);
577 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
578 bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
582 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
583 (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
584 bcm43xx_phy_write(bcm, 0x0034, 0x0001);
586 TODO();//TODO: RSSI AGC
587 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
588 bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
589 bcm43xx_radio_init2060(bcm);
591 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
592 && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
593 if (radio->lofcal == 0xFFFF) {
594 TODO();//TODO: LOF Cal
595 bcm43xx_radio_set_tx_iq(bcm);
597 bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
600 bcm43xx_phy_write(bcm, 0x007A, 0xF111);
602 if (phy->savedpctlreg == 0xFFFF) {
603 bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
604 bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
606 tval = bcm43xx_ilt_read(bcm, 0x3001);
608 bcm43xx_ilt_write(bcm, 0x3001,
609 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
612 bcm43xx_ilt_write(bcm, 0x3001,
613 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
616 bcm43xx_dummy_transmission(bcm);
617 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
618 bcm43xx_ilt_write(bcm, 0x3001, tval);
620 bcm43xx_radio_set_txpower_a(bcm, 0x0018);
622 bcm43xx_radio_clear_tssi(bcm);
625 static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
627 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
630 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
631 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
632 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
633 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
634 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
636 for (offset = 0x0089; offset < 0x00A7; offset++) {
637 bcm43xx_phy_write(bcm, offset, val);
640 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
641 if (radio->channel == 0xFF)
642 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
644 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
645 if (radio->version != 0x2050) {
646 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
647 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
649 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
650 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
651 if (radio->version == 0x2050) {
652 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
653 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
654 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
655 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
656 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
657 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
658 bcm43xx_radio_init2050(bcm);
660 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
661 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
662 bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
663 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
664 bcm43xx_phy_lo_b_measure(bcm);
665 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
666 if (radio->version != 0x2050)
667 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
668 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
669 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
670 if (radio->version != 0x2050)
671 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
672 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
673 bcm43xx_phy_init_pctl(bcm);
676 static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
678 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
681 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
682 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
683 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
684 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
685 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
687 for (offset = 0x0089; offset < 0x00A7; offset++) {
688 bcm43xx_phy_write(bcm, offset, val);
691 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
692 if (radio->channel == 0xFF)
693 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
695 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
696 if (radio->version != 0x2050) {
697 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
698 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
700 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
701 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
702 if (radio->version == 0x2050) {
703 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
704 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
705 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
706 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
707 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
708 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
709 bcm43xx_radio_init2050(bcm);
711 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
712 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
713 if (radio->version == 0x2050)
714 bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
715 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
717 bcm43xx_phy_lo_b_measure(bcm);
719 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
720 if (radio->version == 0x2050)
721 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
722 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
723 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
724 if (radio->version == 0x2050)
725 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
726 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
727 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
728 bcm43xx_calc_nrssi_slope(bcm);
729 bcm43xx_calc_nrssi_threshold(bcm);
731 bcm43xx_phy_init_pctl(bcm);
734 static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
736 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
737 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
742 if (phy->analog == 1)
743 bcm43xx_radio_write16(bcm, 0x007A,
744 bcm43xx_radio_read16(bcm, 0x007A)
746 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
747 (bcm->board_type != 0x0416)) {
749 for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
750 bcm43xx_phy_write(bcm, offset, value);
754 bcm43xx_phy_write(bcm, 0x0035,
755 (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
757 if (radio->version == 0x2050)
758 bcm43xx_phy_write(bcm, 0x0038, 0x0667);
760 if (phy->type == BCM43xx_PHYTYPE_G) {
761 if (radio->version == 0x2050) {
762 bcm43xx_radio_write16(bcm, 0x007A,
763 bcm43xx_radio_read16(bcm, 0x007A)
765 bcm43xx_radio_write16(bcm, 0x0051,
766 bcm43xx_radio_read16(bcm, 0x0051)
769 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
771 bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
772 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
774 bcm43xx_phy_write(bcm, 0x001C, 0x186A);
776 bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
777 bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
778 bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
781 if (bcm->bad_frames_preempt) {
782 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
783 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
786 if (phy->analog == 1) {
787 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
788 bcm43xx_phy_write(bcm, 0x0021, 0x3763);
789 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
790 bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
791 bcm43xx_phy_write(bcm, 0x0024, 0x037E);
793 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
794 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
795 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
797 if (phy->analog == 1)
798 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
800 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
802 if (phy->analog == 0)
803 bcm43xx_write16(bcm, 0x03E4, 0x3000);
805 old_channel = radio->channel;
806 /* Force to channel 7, even if not supported. */
807 bcm43xx_radio_selectchannel(bcm, 7, 0);
809 if (radio->version != 0x2050) {
810 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
811 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
814 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
815 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
817 if (radio->version == 0x2050) {
818 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
819 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
822 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
823 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
825 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
827 bcm43xx_radio_selectchannel(bcm, old_channel, 0);
829 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
830 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
831 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
833 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
835 if (radio->version == 0x2050)
836 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
838 bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
841 static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
843 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
844 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
848 bcm43xx_phy_write(bcm, 0x003E, 0x817A);
849 bcm43xx_radio_write16(bcm, 0x007A,
850 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
851 if (radio->revision == 4 ||
852 radio->revision == 5) {
853 bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
854 bcm43xx_radio_write16(bcm, 0x0052, 0x0070);
855 bcm43xx_radio_write16(bcm, 0x0053, 0x00B3);
856 bcm43xx_radio_write16(bcm, 0x0054, 0x009B);
857 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
858 bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
859 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
860 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
861 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
863 if (radio->revision == 8) {
864 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
865 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
866 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
867 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
868 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
869 bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
870 bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
871 if (bcm->sprom.boardflags & 0x8000) {
872 bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
873 bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
875 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
876 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
878 bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
879 bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
880 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
881 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
884 for (offset = 0x0088; offset < 0x0098; offset++) {
885 bcm43xx_phy_write(bcm, offset, val);
889 for (offset = 0x0098; offset < 0x00A8; offset++) {
890 bcm43xx_phy_write(bcm, offset, val);
894 for (offset = 0x00A8; offset < 0x00C8; offset++) {
895 bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
898 if (phy->type == BCM43xx_PHYTYPE_G) {
899 bcm43xx_radio_write16(bcm, 0x007A,
900 bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
901 bcm43xx_radio_write16(bcm, 0x0051,
902 bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
903 bcm43xx_phy_write(bcm, 0x0802,
904 bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
905 bcm43xx_phy_write(bcm, 0x042B,
906 bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
907 bcm43xx_phy_write(bcm, 0x5B, 0x0000);
908 bcm43xx_phy_write(bcm, 0x5C, 0x0000);
911 old_channel = radio->channel;
912 if (old_channel >= 8)
913 bcm43xx_radio_selectchannel(bcm, 1, 0);
915 bcm43xx_radio_selectchannel(bcm, 13, 0);
917 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
918 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
920 if (radio->revision < 6 || radio-> revision == 8) {
921 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C)
923 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
925 if (radio->revision <= 2) {
926 bcm43xx_radio_write16(bcm, 0x007C, 0x0020);
927 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
928 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
929 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
931 bcm43xx_radio_write16(bcm, 0x007A,
932 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
934 bcm43xx_radio_selectchannel(bcm, old_channel, 0);
936 bcm43xx_phy_write(bcm, 0x0014, 0x0200);
937 if (radio->revision >= 6)
938 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
940 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
941 bcm43xx_phy_write(bcm, 0x0038, 0x0668);
942 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
943 if (radio->revision <= 5)
944 bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
945 if (radio->revision <= 2)
946 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
948 if (phy->analog == 4){
949 bcm43xx_write16(bcm, 0x03E4, 0x0009);
950 bcm43xx_phy_write(bcm, 0x61, bcm43xx_phy_read(bcm, 0x61) & 0xFFF);
952 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
954 if (phy->type == BCM43xx_PHYTYPE_G)
955 bcm43xx_write16(bcm, 0x03E6, 0x0);
956 if (phy->type == BCM43xx_PHYTYPE_B) {
957 bcm43xx_write16(bcm, 0x03E6, 0x8140);
958 bcm43xx_phy_write(bcm, 0x0016, 0x0410);
959 bcm43xx_phy_write(bcm, 0x0017, 0x0820);
960 bcm43xx_phy_write(bcm, 0x0062, 0x0007);
961 (void) bcm43xx_radio_calibrationvalue(bcm);
962 bcm43xx_phy_lo_g_measure(bcm);
963 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
964 bcm43xx_calc_nrssi_slope(bcm);
965 bcm43xx_calc_nrssi_threshold(bcm);
967 bcm43xx_phy_init_pctl(bcm);
971 static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
973 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
974 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
979 u16 loop1_cnt, loop1_done, loop1_omitted;
982 backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
983 backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
984 backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
985 backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
986 backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
987 backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
988 backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
989 backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
990 backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
991 backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
992 backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
993 backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
994 backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
995 backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
996 backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
997 bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
998 backup_bband = radio->baseband_atten;
999 backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
1000 backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
1001 backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
1003 bcm43xx_phy_write(bcm, 0x0429,
1004 bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
1005 bcm43xx_phy_write(bcm, 0x0001,
1006 bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
1007 bcm43xx_phy_write(bcm, 0x0811,
1008 bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
1009 bcm43xx_phy_write(bcm, 0x0812,
1010 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
1011 bcm43xx_phy_write(bcm, 0x0811,
1012 bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
1013 bcm43xx_phy_write(bcm, 0x0812,
1014 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
1015 bcm43xx_phy_write(bcm, 0x0814,
1016 bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
1017 bcm43xx_phy_write(bcm, 0x0815,
1018 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
1019 bcm43xx_phy_write(bcm, 0x0814,
1020 bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
1021 bcm43xx_phy_write(bcm, 0x0815,
1022 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
1023 bcm43xx_phy_write(bcm, 0x0811,
1024 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
1025 bcm43xx_phy_write(bcm, 0x0812,
1026 bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
1028 bcm43xx_phy_write(bcm, 0x0811,
1029 (bcm43xx_phy_read(bcm, 0x0811)
1030 & 0xFFCF) | 0x0030);
1031 bcm43xx_phy_write(bcm, 0x0812,
1032 (bcm43xx_phy_read(bcm, 0x0812)
1033 & 0xFFCF) | 0x0010);
1035 bcm43xx_phy_write(bcm, 0x005A, 0x0780);
1036 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1037 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1038 if (phy->analog == 0) {
1039 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
1041 bcm43xx_phy_write(bcm, 0x000A,
1042 bcm43xx_phy_read(bcm, 0x000A)
1045 bcm43xx_phy_write(bcm, 0x0814,
1046 bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
1047 bcm43xx_phy_write(bcm, 0x0815,
1048 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
1049 bcm43xx_phy_write(bcm, 0x0003,
1050 (bcm43xx_phy_read(bcm, 0x0003)
1051 & 0xFF9F) | 0x0040);
1052 if (radio->version == 0x2050 && radio->revision == 2) {
1053 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1054 bcm43xx_radio_write16(bcm, 0x0043,
1055 (bcm43xx_radio_read16(bcm, 0x0043)
1056 & 0xFFF0) | 0x0009);
1058 } else if (radio->revision == 8) {
1059 bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
1064 bcm43xx_phy_set_baseband_attenuation(bcm, 11);
1067 bcm43xx_phy_write(bcm, 0x080F, 0xC020);
1069 bcm43xx_phy_write(bcm, 0x080F, 0x8020);
1070 bcm43xx_phy_write(bcm, 0x0810, 0x0000);
1072 bcm43xx_phy_write(bcm, 0x002B,
1073 (bcm43xx_phy_read(bcm, 0x002B)
1074 & 0xFFC0) | 0x0001);
1075 bcm43xx_phy_write(bcm, 0x002B,
1076 (bcm43xx_phy_read(bcm, 0x002B)
1077 & 0xC0FF) | 0x0800);
1078 bcm43xx_phy_write(bcm, 0x0811,
1079 bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
1080 bcm43xx_phy_write(bcm, 0x0812,
1081 bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
1082 if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
1083 if (phy->rev >= 7) {
1084 bcm43xx_phy_write(bcm, 0x0811,
1085 bcm43xx_phy_read(bcm, 0x0811)
1087 bcm43xx_phy_write(bcm, 0x0812,
1088 bcm43xx_phy_read(bcm, 0x0812)
1092 bcm43xx_radio_write16(bcm, 0x007A,
1093 bcm43xx_radio_read16(bcm, 0x007A)
1096 for (i = 0; i < loop1_cnt; i++) {
1097 bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
1098 bcm43xx_phy_write(bcm, 0x0812,
1099 (bcm43xx_phy_read(bcm, 0x0812)
1100 & 0xF0FF) | (i << 8));
1101 bcm43xx_phy_write(bcm, 0x0015,
1102 (bcm43xx_phy_read(bcm, 0x0015)
1103 & 0x0FFF) | 0xA000);
1104 bcm43xx_phy_write(bcm, 0x0015,
1105 (bcm43xx_phy_read(bcm, 0x0015)
1106 & 0x0FFF) | 0xF000);
1108 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1112 loop1_omitted = loop1_cnt - loop1_done;
1115 if (loop1_done >= 8) {
1116 bcm43xx_phy_write(bcm, 0x0812,
1117 bcm43xx_phy_read(bcm, 0x0812)
1119 for (i = loop1_done - 8; i < 16; i++) {
1120 bcm43xx_phy_write(bcm, 0x0812,
1121 (bcm43xx_phy_read(bcm, 0x0812)
1122 & 0xF0FF) | (i << 8));
1123 bcm43xx_phy_write(bcm, 0x0015,
1124 (bcm43xx_phy_read(bcm, 0x0015)
1125 & 0x0FFF) | 0xA000);
1126 bcm43xx_phy_write(bcm, 0x0015,
1127 (bcm43xx_phy_read(bcm, 0x0015)
1128 & 0x0FFF) | 0xF000);
1130 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1135 bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
1136 bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
1137 bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
1138 bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
1139 bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
1140 bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
1141 bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
1142 bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
1143 bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
1144 bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
1145 bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
1147 bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
1149 bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
1150 bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
1151 bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
1153 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
1155 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
1156 bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
1157 bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
1158 bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
1160 phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
1161 phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
1164 static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1166 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1167 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1171 bcm43xx_phy_initb5(bcm);
1173 bcm43xx_phy_initb6(bcm);
1174 if (phy->rev >= 2 || phy->connected)
1175 bcm43xx_phy_inita(bcm);
1177 if (phy->rev >= 2) {
1178 bcm43xx_phy_write(bcm, 0x0814, 0x0000);
1179 bcm43xx_phy_write(bcm, 0x0815, 0x0000);
1181 if (phy->rev == 2) {
1182 bcm43xx_phy_write(bcm, 0x0811, 0x0000);
1183 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1185 if (phy->rev >= 3) {
1186 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1187 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1189 if (phy->connected) {
1190 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
1192 bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
1193 bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
1195 bcm43xx_phy_write(bcm, 0x04CC,
1196 (bcm43xx_phy_read(bcm, 0x04CC)
1197 & 0x00FF) | 0x1F00);
1201 if (phy->rev < 3 && phy->connected)
1202 bcm43xx_phy_write(bcm, 0x047E, 0x0078);
1203 if (radio->revision == 8) {
1204 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
1205 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
1207 if (phy->rev >= 2 && phy->connected)
1208 bcm43xx_calc_loopback_gain(bcm);
1209 if (radio->revision != 8) {
1210 if (radio->initval == 0xFFFF)
1211 radio->initval = bcm43xx_radio_init2050(bcm);
1213 bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
1215 if (radio->txctl2 == 0xFFFF) {
1216 bcm43xx_phy_lo_g_measure(bcm);
1218 if (radio->version == 0x2050 && radio->revision == 8) {
1219 bcm43xx_radio_write16(bcm, 0x0052,
1220 (radio->txctl1 << 4) | radio->txctl2);
1222 bcm43xx_radio_write16(bcm, 0x0052,
1223 (bcm43xx_radio_read16(bcm, 0x0052)
1224 & 0xFFF0) | radio->txctl1);
1226 if (phy->rev >= 6) {
1227 bcm43xx_phy_write(bcm, 0x0036,
1228 (bcm43xx_phy_read(bcm, 0x0036)
1229 & 0xF000) | (radio->txctl2 << 12));
1231 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
1232 bcm43xx_phy_write(bcm, 0x002E, 0x8075);
1234 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1236 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1238 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1240 if (phy->connected) {
1241 bcm43xx_phy_lo_adjust(bcm, 0);
1242 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1245 if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
1246 /* The specs state to update the NRSSI LT with
1247 * the value 0x7FFFFFFF here. I think that is some weird
1248 * compiler optimization in the original driver.
1249 * Essentially, what we do here is resetting all NRSSI LT
1250 * entries to -32 (see the limit_value() in nrssi_hw_update())
1252 bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
1253 bcm43xx_calc_nrssi_threshold(bcm);
1254 } else if (phy->connected) {
1255 if (radio->nrssi[0] == -1000) {
1256 assert(radio->nrssi[1] == -1000);
1257 bcm43xx_calc_nrssi_slope(bcm);
1259 assert(radio->nrssi[1] != -1000);
1260 bcm43xx_calc_nrssi_threshold(bcm);
1263 if (radio->revision == 8)
1264 bcm43xx_phy_write(bcm, 0x0805, 0x3230);
1265 bcm43xx_phy_init_pctl(bcm);
1266 if (bcm->chip_id == 0x4306 && bcm->chip_package == 2) {
1267 bcm43xx_phy_write(bcm, 0x0429,
1268 bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
1269 bcm43xx_phy_write(bcm, 0x04C3,
1270 bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
1274 static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
1278 unsigned long flags;
1280 local_irq_save(flags);
1281 for (i = 0; i < 10; i++){
1282 bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
1284 bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
1286 bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
1288 ret += bcm43xx_phy_read(bcm, 0x002C);
1290 local_irq_restore(flags);
1291 bcm43xx_voluntary_preempt();
1296 void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
1298 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1299 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1300 u16 regstack[12] = { 0 };
1305 regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
1306 regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
1308 if (radio->version == 0x2053) {
1309 regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
1310 regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
1311 regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
1312 regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
1313 regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
1314 regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
1316 regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
1317 regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
1318 regstack[10] = bcm43xx_read16(bcm, 0x03EC);
1319 regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
1321 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
1322 bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
1323 bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
1324 bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
1326 bcm43xx_phy_write(bcm, 0x0015, 0xB000);
1327 bcm43xx_phy_write(bcm, 0x002B, 0x0004);
1329 if (radio->version == 0x2053) {
1330 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1331 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1334 phy->minlowsig[0] = 0xFFFF;
1336 for (i = 0; i < 4; i++) {
1337 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1338 bcm43xx_phy_lo_b_r15_loop(bcm);
1340 for (i = 0; i < 10; i++) {
1341 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1342 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1343 if (mls < phy->minlowsig[0]) {
1344 phy->minlowsig[0] = mls;
1345 phy->minlowsigpos[0] = i;
1348 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
1350 phy->minlowsig[1] = 0xFFFF;
1352 for (i = -4; i < 5; i += 2) {
1353 for (j = -4; j < 5; j += 2) {
1355 fval = (0x0100 * i) + j + 0x0100;
1357 fval = (0x0100 * i) + j;
1358 bcm43xx_phy_write(bcm, 0x002F, fval);
1359 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1360 if (mls < phy->minlowsig[1]) {
1361 phy->minlowsig[1] = mls;
1362 phy->minlowsigpos[1] = fval;
1366 phy->minlowsigpos[1] += 0x0101;
1368 bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
1369 if (radio->version == 0x2053) {
1370 bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
1371 bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
1372 bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
1373 bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
1374 bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
1375 bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
1377 bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
1378 bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
1380 bcm43xx_radio_write16(bcm, 0x0052,
1381 (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
1384 bcm43xx_write16(bcm, 0x03EC, regstack[10]);
1386 bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
1390 u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
1392 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1394 unsigned long flags;
1396 local_irq_save(flags);
1397 if (phy->connected) {
1398 bcm43xx_phy_write(bcm, 0x15, 0xE300);
1400 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
1402 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
1404 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
1406 bcm43xx_phy_write(bcm, 0x0015, 0xF300);
1409 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
1411 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
1413 bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
1416 ret = bcm43xx_phy_read(bcm, 0x002D);
1417 local_irq_restore(flags);
1418 bcm43xx_voluntary_preempt();
1423 static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
1428 for (i = 0; i < 8; i++)
1429 ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
1434 /* Write the LocalOscillator CONTROL */
1436 void bcm43xx_lo_write(struct bcm43xx_private *bcm,
1437 struct bcm43xx_lopair *pair)
1441 value = (u8)(pair->low);
1442 value |= ((u8)(pair->high)) << 8;
1444 #ifdef CONFIG_BCM43XX_DEBUG
1446 if (pair->low < -8 || pair->low > 8 ||
1447 pair->high < -8 || pair->high > 8) {
1448 printk(KERN_WARNING PFX
1449 "WARNING: Writing invalid LOpair "
1450 "(low: %d, high: %d, index: %lu)\n",
1451 pair->low, pair->high,
1452 (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
1457 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
1461 struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
1462 u16 baseband_attenuation,
1463 u16 radio_attenuation,
1466 static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
1467 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1469 if (baseband_attenuation > 6)
1470 baseband_attenuation = 6;
1471 assert(radio_attenuation < 10);
1474 return bcm43xx_get_lopair(phy,
1476 baseband_attenuation);
1478 return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
1482 struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
1484 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1486 return bcm43xx_find_lopair(bcm,
1487 radio->baseband_atten,
1493 void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
1495 struct bcm43xx_lopair *pair;
1498 /* Use fixed values. Only for initialization. */
1499 pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
1501 pair = bcm43xx_current_lopair(bcm);
1502 bcm43xx_lo_write(bcm, pair);
1505 static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
1507 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1511 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1513 smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1514 for (i = 0; i < 16; i++) {
1515 bcm43xx_radio_write16(bcm, 0x0052, i);
1517 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1518 if (tmp < smallest) {
1523 radio->txctl2 = txctl2;
1527 void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
1528 const struct bcm43xx_lopair *in_pair,
1529 struct bcm43xx_lopair *out_pair,
1532 static const struct bcm43xx_lopair transitions[8] = {
1533 { .high = 1, .low = 1, },
1534 { .high = 1, .low = 0, },
1535 { .high = 1, .low = -1, },
1536 { .high = 0, .low = -1, },
1537 { .high = -1, .low = -1, },
1538 { .high = -1, .low = 0, },
1539 { .high = -1, .low = 1, },
1540 { .high = 0, .low = 1, },
1542 struct bcm43xx_lopair lowest_transition = {
1543 .high = in_pair->high,
1544 .low = in_pair->low,
1546 struct bcm43xx_lopair tmp_pair;
1547 struct bcm43xx_lopair transition;
1552 u32 lowest_deviation;
1555 /* Note that in_pair and out_pair can point to the same pair. Be careful. */
1557 bcm43xx_lo_write(bcm, &lowest_transition);
1558 lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1561 assert(state >= 0 && state <= 8);
1565 } else if (state % 2 == 0) {
1578 tmp_pair.high = lowest_transition.high;
1579 tmp_pair.low = lowest_transition.low;
1581 assert(j >= 1 && j <= 8);
1582 transition.high = tmp_pair.high + transitions[j - 1].high;
1583 transition.low = tmp_pair.low + transitions[j - 1].low;
1584 if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
1585 bcm43xx_lo_write(bcm, &transition);
1586 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1587 if (tmp < lowest_deviation) {
1588 lowest_deviation = tmp;
1592 lowest_transition.high = transition.high;
1593 lowest_transition.low = transition.low;
1603 } while (i-- && found_lower);
1605 out_pair->high = lowest_transition.high;
1606 out_pair->low = lowest_transition.low;
1609 /* Set the baseband attenuation value on chip. */
1610 void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
1611 u16 baseband_attenuation)
1613 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1616 if (phy->analog == 0) {
1617 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
1618 value |= (baseband_attenuation & 0x000F);
1619 bcm43xx_write16(bcm, 0x03E6, value);
1623 if (phy->analog > 1) {
1624 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
1625 value |= (baseband_attenuation << 2) & 0x003C;
1627 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
1628 value |= (baseband_attenuation << 3) & 0x0078;
1630 bcm43xx_phy_write(bcm, 0x0060, value);
1633 /* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
1634 void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
1636 static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
1637 const int is_initializing = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZING);
1638 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1639 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1640 u16 h, i, oldi = 0, j;
1641 struct bcm43xx_lopair control;
1642 struct bcm43xx_lopair *tmp_control;
1644 u16 regstack[16] = { 0 };
1647 //XXX: What are these?
1650 oldchannel = radio->channel;
1652 if (phy->connected) {
1653 regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
1654 regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
1655 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1656 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1658 regstack[3] = bcm43xx_read16(bcm, 0x03E2);
1659 bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
1660 regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1661 regstack[5] = bcm43xx_phy_read(bcm, 0x15);
1662 regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
1663 regstack[7] = bcm43xx_phy_read(bcm, 0x35);
1664 regstack[8] = bcm43xx_phy_read(bcm, 0x60);
1665 regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
1666 regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
1667 regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
1668 if (phy->connected) {
1669 regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
1670 regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
1671 regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
1672 regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
1674 bcm43xx_radio_selectchannel(bcm, 6, 0);
1675 if (phy->connected) {
1676 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1677 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1678 bcm43xx_dummy_transmission(bcm);
1680 bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
1682 bcm43xx_phy_set_baseband_attenuation(bcm, 2);
1684 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
1685 bcm43xx_phy_write(bcm, 0x002E, 0x007F);
1686 bcm43xx_phy_write(bcm, 0x080F, 0x0078);
1687 bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
1688 bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
1689 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1690 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1691 if (phy->connected) {
1692 bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
1693 bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
1694 bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
1695 bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
1697 if (is_initializing)
1698 bcm43xx_phy_lo_g_measure_txctl2(bcm);
1699 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1704 for (h = 0; h < 10; h++) {
1705 /* Loop over each possible RadioAttenuation (0-9) */
1707 if (is_initializing) {
1711 } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
1712 ((i % 2 == 0) && (oldi % 2 == 0))) {
1713 tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
1714 memcpy(&control, tmp_control, sizeof(control));
1716 tmp_control = bcm43xx_get_lopair(phy, 3, 0);
1717 memcpy(&control, tmp_control, sizeof(control));
1720 /* Loop over each possible BasebandAttenuation/2 */
1721 for (j = 0; j < 4; j++) {
1722 if (is_initializing) {
1734 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1735 if (!tmp_control->used)
1737 memcpy(&control, tmp_control, sizeof(control));
1741 bcm43xx_radio_write16(bcm, 0x43, i);
1742 bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
1744 bcm43xx_voluntary_preempt();
1746 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1748 tmp = (regstack[10] & 0xFFF0);
1751 bcm43xx_radio_write16(bcm, 0x007A, tmp);
1753 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1754 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1758 /* Loop over each possible RadioAttenuation (10-13) */
1759 for (i = 10; i < 14; i++) {
1760 /* Loop over each possible BasebandAttenuation/2 */
1761 for (j = 0; j < 4; j++) {
1762 if (is_initializing) {
1763 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1764 memcpy(&control, tmp_control, sizeof(control));
1765 tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
1776 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1777 if (!tmp_control->used)
1779 memcpy(&control, tmp_control, sizeof(control));
1783 bcm43xx_radio_write16(bcm, 0x43, i - 9);
1784 bcm43xx_radio_write16(bcm, 0x52,
1786 | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
1788 bcm43xx_voluntary_preempt();
1790 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1792 tmp = (regstack[10] & 0xFFF0);
1795 bcm43xx_radio_write16(bcm, 0x7A, tmp);
1797 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1798 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1803 if (phy->connected) {
1804 bcm43xx_phy_write(bcm, 0x0015, 0xE300);
1805 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
1807 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
1809 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
1810 bcm43xx_voluntary_preempt();
1812 bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
1813 bcm43xx_phy_lo_adjust(bcm, is_initializing);
1814 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1816 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1818 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1819 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
1820 bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
1821 bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
1822 bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
1823 bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
1824 bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
1825 bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
1826 regstack[11] &= 0x00F0;
1827 regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
1828 bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
1829 bcm43xx_write16(bcm, 0x03E2, regstack[3]);
1830 if (phy->connected) {
1831 bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
1832 bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
1833 bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
1834 bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
1835 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
1836 bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
1838 bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
1840 #ifdef CONFIG_BCM43XX_DEBUG
1842 /* Sanity check for all lopairs. */
1843 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1844 tmp_control = phy->_lo_pairs + i;
1845 if (tmp_control->low < -8 || tmp_control->low > 8 ||
1846 tmp_control->high < -8 || tmp_control->high > 8) {
1847 printk(KERN_WARNING PFX
1848 "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
1849 tmp_control->low, tmp_control->high, i);
1853 #endif /* CONFIG_BCM43XX_DEBUG */
1857 void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
1859 struct bcm43xx_lopair *pair;
1861 pair = bcm43xx_current_lopair(bcm);
1865 void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
1867 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1868 struct bcm43xx_lopair *pair;
1871 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1872 pair = phy->_lo_pairs + i;
1877 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1878 * This function converts a TSSI value to dBm in Q5.2
1880 static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
1882 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1886 tmp = phy->idle_tssi;
1888 tmp -= phy->savedpctlreg;
1890 switch (phy->type) {
1891 case BCM43xx_PHYTYPE_A:
1893 tmp = limit_value(tmp, 0x00, 0xFF);
1894 dbm = phy->tssi2dbm[tmp];
1895 TODO(); //TODO: There's a FIXME on the specs
1897 case BCM43xx_PHYTYPE_B:
1898 case BCM43xx_PHYTYPE_G:
1899 tmp = limit_value(tmp, 0x00, 0x3F);
1900 dbm = phy->tssi2dbm[tmp];
1909 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1910 void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
1912 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1913 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1915 if (phy->savedpctlreg == 0xFFFF)
1917 if ((bcm->board_type == 0x0416) &&
1918 (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
1921 switch (phy->type) {
1922 case BCM43xx_PHYTYPE_A: {
1924 TODO(); //TODO: Nothing for A PHYs yet :-/
1928 case BCM43xx_PHYTYPE_B:
1929 case BCM43xx_PHYTYPE_G: {
1935 s16 desired_pwr, estimated_pwr, pwr_adjust;
1936 s16 radio_att_delta, baseband_att_delta;
1937 s16 radio_attenuation, baseband_attenuation;
1938 unsigned long phylock_flags;
1940 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
1941 v0 = (s8)(tmp & 0x00FF);
1942 v1 = (s8)((tmp & 0xFF00) >> 8);
1943 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
1944 v2 = (s8)(tmp & 0x00FF);
1945 v3 = (s8)((tmp & 0xFF00) >> 8);
1948 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
1949 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
1950 v0 = (s8)(tmp & 0x00FF);
1951 v1 = (s8)((tmp & 0xFF00) >> 8);
1952 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
1953 v2 = (s8)(tmp & 0x00FF);
1954 v3 = (s8)((tmp & 0xFF00) >> 8);
1955 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
1957 v0 = (v0 + 0x20) & 0x3F;
1958 v1 = (v1 + 0x20) & 0x3F;
1959 v2 = (v2 + 0x20) & 0x3F;
1960 v3 = (v3 + 0x20) & 0x3F;
1963 bcm43xx_radio_clear_tssi(bcm);
1965 average = (v0 + v1 + v2 + v3 + 2) / 4;
1967 if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
1970 estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
1972 max_pwr = bcm->sprom.maxpower_bgphy;
1974 if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
1975 (phy->type == BCM43xx_PHYTYPE_G))
1979 max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
1980 where REG is the max power as per the regulatory domain
1983 desired_pwr = limit_value(radio->txpower_desired, 0, max_pwr);
1984 /* Check if we need to adjust the current power. */
1985 pwr_adjust = desired_pwr - estimated_pwr;
1986 radio_att_delta = -(pwr_adjust + 7) >> 3;
1987 baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
1988 if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
1989 bcm43xx_phy_lo_mark_current_used(bcm);
1993 /* Calculate the new attenuation values. */
1994 baseband_attenuation = radio->baseband_atten;
1995 baseband_attenuation += baseband_att_delta;
1996 radio_attenuation = radio->radio_atten;
1997 radio_attenuation += radio_att_delta;
1999 /* Get baseband and radio attenuation values into their permitted ranges.
2000 * baseband 0-11, radio 0-9.
2001 * Radio attenuation affects power level 4 times as much as baseband.
2003 if (radio_attenuation < 0) {
2004 baseband_attenuation -= (4 * -radio_attenuation);
2005 radio_attenuation = 0;
2006 } else if (radio_attenuation > 9) {
2007 baseband_attenuation += (4 * (radio_attenuation - 9));
2008 radio_attenuation = 9;
2010 while (baseband_attenuation < 0 && radio_attenuation > 0) {
2011 baseband_attenuation += 4;
2012 radio_attenuation--;
2014 while (baseband_attenuation > 11 && radio_attenuation < 9) {
2015 baseband_attenuation -= 4;
2016 radio_attenuation++;
2019 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2021 txpower = radio->txctl1;
2022 if ((radio->version == 0x2050) && (radio->revision == 2)) {
2023 if (radio_attenuation <= 1) {
2026 radio_attenuation += 2;
2027 baseband_attenuation += 2;
2028 } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2029 baseband_attenuation += 4 * (radio_attenuation - 2);
2030 radio_attenuation = 2;
2032 } else if (radio_attenuation > 4 && txpower != 0) {
2034 if (baseband_attenuation < 3) {
2035 radio_attenuation -= 3;
2036 baseband_attenuation += 2;
2038 radio_attenuation -= 2;
2039 baseband_attenuation -= 2;
2043 radio->txctl1 = txpower;
2044 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2045 radio_attenuation = limit_value(radio_attenuation, 0, 9);
2047 bcm43xx_phy_lock(bcm, phylock_flags);
2048 bcm43xx_radio_lock(bcm);
2049 bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
2050 radio_attenuation, txpower);
2051 bcm43xx_phy_lo_mark_current_used(bcm);
2052 bcm43xx_radio_unlock(bcm);
2053 bcm43xx_phy_unlock(bcm, phylock_flags);
2062 s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
2067 return (num+den/2)/den;
2071 s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
2073 s32 m1, m2, f = 256, q, delta;
2076 m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2077 m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2081 q = bcm43xx_tssi2dbm_ad(f * 4096 -
2082 bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2086 } while (delta >= 2);
2087 entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2091 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2092 int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
2094 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2095 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2096 s16 pab0, pab1, pab2;
2100 if (phy->type == BCM43xx_PHYTYPE_A) {
2101 pab0 = (s16)(bcm->sprom.pa1b0);
2102 pab1 = (s16)(bcm->sprom.pa1b1);
2103 pab2 = (s16)(bcm->sprom.pa1b2);
2105 pab0 = (s16)(bcm->sprom.pa0b0);
2106 pab1 = (s16)(bcm->sprom.pa0b1);
2107 pab2 = (s16)(bcm->sprom.pa0b2);
2110 if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
2111 phy->idle_tssi = 0x34;
2112 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2116 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2117 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2118 /* The pabX values are set in SPROM. Use them. */
2119 if (phy->type == BCM43xx_PHYTYPE_A) {
2120 if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
2121 (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
2122 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
2124 phy->idle_tssi = 62;
2126 if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
2127 (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
2128 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
2130 phy->idle_tssi = 62;
2132 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2133 if (dyn_tssi2dbm == NULL) {
2134 printk(KERN_ERR PFX "Could not allocate memory"
2135 "for tssi2dbm table\n");
2138 for (idx = 0; idx < 64; idx++)
2139 if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2140 phy->tssi2dbm = NULL;
2141 printk(KERN_ERR PFX "Could not generate "
2142 "tssi2dBm table\n");
2143 kfree(dyn_tssi2dbm);
2146 phy->tssi2dbm = dyn_tssi2dbm;
2147 phy->dyn_tssi_tbl = 1;
2149 /* pabX values not set in SPROM. */
2150 switch (phy->type) {
2151 case BCM43xx_PHYTYPE_A:
2152 /* APHY needs a generated table. */
2153 phy->tssi2dbm = NULL;
2154 printk(KERN_ERR PFX "Could not generate tssi2dBm "
2155 "table (wrong SPROM info)!\n");
2157 case BCM43xx_PHYTYPE_B:
2158 phy->idle_tssi = 0x34;
2159 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2161 case BCM43xx_PHYTYPE_G:
2162 phy->idle_tssi = 0x34;
2163 phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
2171 int bcm43xx_phy_init(struct bcm43xx_private *bcm)
2173 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2176 switch (phy->type) {
2177 case BCM43xx_PHYTYPE_A:
2178 if (phy->rev == 2 || phy->rev == 3) {
2179 bcm43xx_phy_inita(bcm);
2183 case BCM43xx_PHYTYPE_B:
2186 bcm43xx_phy_initb2(bcm);
2190 bcm43xx_phy_initb4(bcm);
2194 bcm43xx_phy_initb5(bcm);
2198 bcm43xx_phy_initb6(bcm);
2203 case BCM43xx_PHYTYPE_G:
2204 bcm43xx_phy_initg(bcm);
2209 printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
2214 void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
2216 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2222 antennadiv = phy->antenna_diversity;
2224 if (antennadiv == 0xFFFF)
2226 assert(antennadiv <= 3);
2228 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2229 BCM43xx_UCODEFLAGS_OFFSET);
2230 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2231 BCM43xx_UCODEFLAGS_OFFSET,
2232 ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
2234 switch (phy->type) {
2235 case BCM43xx_PHYTYPE_A:
2236 case BCM43xx_PHYTYPE_G:
2237 if (phy->type == BCM43xx_PHYTYPE_A)
2242 if (antennadiv == 2)
2243 value = (3/*automatic*/ << 7);
2245 value = (antennadiv << 7);
2246 bcm43xx_phy_write(bcm, offset + 1,
2247 (bcm43xx_phy_read(bcm, offset + 1)
2250 if (antennadiv >= 2) {
2251 if (antennadiv == 2)
2252 value = (antennadiv << 7);
2254 value = (0/*force0*/ << 7);
2255 bcm43xx_phy_write(bcm, offset + 0x2B,
2256 (bcm43xx_phy_read(bcm, offset + 0x2B)
2260 if (phy->type == BCM43xx_PHYTYPE_G) {
2261 if (antennadiv >= 2)
2262 bcm43xx_phy_write(bcm, 0x048C,
2263 bcm43xx_phy_read(bcm, 0x048C)
2266 bcm43xx_phy_write(bcm, 0x048C,
2267 bcm43xx_phy_read(bcm, 0x048C)
2269 if (phy->rev >= 2) {
2270 bcm43xx_phy_write(bcm, 0x0461,
2271 bcm43xx_phy_read(bcm, 0x0461)
2273 bcm43xx_phy_write(bcm, 0x04AD,
2274 (bcm43xx_phy_read(bcm, 0x04AD)
2275 & 0x00FF) | 0x0015);
2277 bcm43xx_phy_write(bcm, 0x0427, 0x0008);
2279 bcm43xx_phy_write(bcm, 0x0427,
2280 (bcm43xx_phy_read(bcm, 0x0427)
2281 & 0x00FF) | 0x0008);
2283 else if (phy->rev >= 6)
2284 bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
2287 bcm43xx_phy_write(bcm, 0x002B,
2288 (bcm43xx_phy_read(bcm, 0x002B)
2289 & 0x00FF) | 0x0024);
2291 bcm43xx_phy_write(bcm, 0x0061,
2292 bcm43xx_phy_read(bcm, 0x0061)
2294 if (phy->rev == 3) {
2295 bcm43xx_phy_write(bcm, 0x0093, 0x001D);
2296 bcm43xx_phy_write(bcm, 0x0027, 0x0008);
2298 bcm43xx_phy_write(bcm, 0x0093, 0x003A);
2299 bcm43xx_phy_write(bcm, 0x0027,
2300 (bcm43xx_phy_read(bcm, 0x0027)
2301 & 0x00FF) | 0x0008);
2306 case BCM43xx_PHYTYPE_B:
2307 if (bcm->current_core->rev == 2)
2308 value = (3/*automatic*/ << 7);
2310 value = (antennadiv << 7);
2311 bcm43xx_phy_write(bcm, 0x03E2,
2312 (bcm43xx_phy_read(bcm, 0x03E2)
2319 if (antennadiv >= 2) {
2320 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2321 BCM43xx_UCODEFLAGS_OFFSET);
2322 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2323 BCM43xx_UCODEFLAGS_OFFSET,
2324 ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
2327 phy->antenna_diversity = antennadiv;