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_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
209 bcm43xx_phy_write(bcm, 0x0028, 0x8018);
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 static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
324 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
327 assert(phy->type == BCM43xx_PHYTYPE_G);
329 bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
330 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
331 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
332 bcm43xx_phy_write(bcm, 0x042C, 0x005A);
333 bcm43xx_phy_write(bcm, 0x0427, 0x001A);
335 for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
336 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
337 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
338 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
339 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
340 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
342 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
343 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
346 bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
347 bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
348 } else if (phy->rev > 2) {
349 bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
350 bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
351 bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
353 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
355 for (i = 0; i < 64; i++)
356 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
357 for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
358 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
362 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
363 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
364 else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
365 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
366 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
368 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
369 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
372 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
373 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
374 else if ((phy->rev > 2) && (phy->rev <= 7))
375 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
376 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
379 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
380 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
381 for (i = 0; i < 4; i++) {
382 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
383 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
384 bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
385 bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
387 bcm43xx_phy_agcsetup(bcm);
389 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
390 (bcm->board_type == 0x0416) &&
391 (bcm->board_revision == 0x0017))
394 bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
395 bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
397 for (i = 0; i <= 0x2F; i++)
398 bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
399 bcm43xx_phy_agcsetup(bcm);
400 bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
401 bcm43xx_phy_write(bcm, 0x0403, 0x1000);
402 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
403 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
405 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
406 (bcm->board_type == 0x0416) &&
407 (bcm->board_revision == 0x0017))
410 bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
411 bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
415 /* Initialize the noisescaletable for APHY */
416 static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
418 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
421 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
422 for (i = 0; i < 12; i++) {
424 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
426 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
429 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
431 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
432 for (i = 0; i < 11; i++) {
434 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
436 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
439 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
441 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
444 static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
446 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
449 assert(phy->type == BCM43xx_PHYTYPE_A);
452 bcm43xx_phy_write(bcm, 0x008E, 0x3800);
453 bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
454 bcm43xx_phy_write(bcm, 0x0036, 0x0400);
456 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
458 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
459 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
460 bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
461 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
463 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
464 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
465 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
466 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
468 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
469 bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
470 bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
472 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
473 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
474 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
475 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
476 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
478 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
479 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
480 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
481 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
482 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
483 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
484 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
486 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
487 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
488 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
490 for (i = 0; i < 16; i++)
491 bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
493 bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
494 bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
495 bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
496 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
498 for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
499 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
500 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
501 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
502 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
503 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
504 bcm43xx_phy_init_noisescaletbl(bcm);
505 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
506 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
509 for (i = 0; i < 64; i++)
510 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
512 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
514 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
515 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
516 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
518 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
519 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
520 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
521 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
522 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
524 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
525 for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
526 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
527 bcm43xx_phy_init_noisescaletbl(bcm);
528 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
529 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
531 bcm43xx_phy_write(bcm, 0x0003, 0x1808);
533 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
534 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
535 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
536 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
537 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
539 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
540 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
541 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
542 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
543 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
544 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
545 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
547 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
548 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
549 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
551 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
552 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
559 /* Initialize APHY. This is also called for the GPHY in some cases. */
560 static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
562 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
563 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
566 if (phy->type == BCM43xx_PHYTYPE_A) {
567 bcm43xx_phy_setupa(bcm);
569 bcm43xx_phy_setupg(bcm);
570 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
571 bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
575 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
576 (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
577 bcm43xx_phy_write(bcm, 0x0034, 0x0001);
579 TODO();//TODO: RSSI AGC
580 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
581 bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
582 bcm43xx_radio_init2060(bcm);
584 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
585 && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
586 if (radio->lofcal == 0xFFFF) {
587 TODO();//TODO: LOF Cal
588 bcm43xx_radio_set_tx_iq(bcm);
590 bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
593 bcm43xx_phy_write(bcm, 0x007A, 0xF111);
595 if (phy->savedpctlreg == 0xFFFF) {
596 bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
597 bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
599 tval = bcm43xx_ilt_read(bcm, 0x3001);
601 bcm43xx_ilt_write(bcm, 0x3001,
602 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
605 bcm43xx_ilt_write(bcm, 0x3001,
606 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
609 bcm43xx_dummy_transmission(bcm);
610 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
611 bcm43xx_ilt_write(bcm, 0x3001, tval);
613 bcm43xx_radio_set_txpower_a(bcm, 0x0018);
615 bcm43xx_radio_clear_tssi(bcm);
618 static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
620 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
623 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
624 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
625 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
626 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
627 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
629 for (offset = 0x0089; offset < 0x00A7; offset++) {
630 bcm43xx_phy_write(bcm, offset, val);
633 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
634 if (radio->channel == 0xFF)
635 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
637 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
638 if (radio->version != 0x2050) {
639 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
640 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
642 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
643 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
644 if (radio->version == 0x2050) {
645 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
646 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
647 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
648 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
649 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
650 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
651 bcm43xx_radio_init2050(bcm);
653 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
654 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
655 bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
656 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
657 bcm43xx_phy_lo_b_measure(bcm);
658 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
659 if (radio->version != 0x2050)
660 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
661 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
662 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
663 if (radio->version != 0x2050)
664 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
665 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
666 bcm43xx_phy_init_pctl(bcm);
669 static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
671 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
674 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
675 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
676 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
677 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
678 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
680 for (offset = 0x0089; offset < 0x00A7; offset++) {
681 bcm43xx_phy_write(bcm, offset, val);
684 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
685 if (radio->channel == 0xFF)
686 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
688 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
689 if (radio->version != 0x2050) {
690 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
691 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
693 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
694 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
695 if (radio->version == 0x2050) {
696 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
697 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
698 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
699 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
700 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
701 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
702 bcm43xx_radio_init2050(bcm);
704 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
705 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
706 if (radio->version == 0x2050)
707 bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
708 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
710 bcm43xx_phy_lo_b_measure(bcm);
712 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
713 if (radio->version == 0x2050)
714 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
715 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
716 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
717 if (radio->version == 0x2050)
718 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
719 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
720 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
721 bcm43xx_calc_nrssi_slope(bcm);
722 bcm43xx_calc_nrssi_threshold(bcm);
724 bcm43xx_phy_init_pctl(bcm);
727 static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
729 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
730 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
733 if (phy->version == 1 &&
734 radio->version == 0x2050) {
735 bcm43xx_radio_write16(bcm, 0x007A,
736 bcm43xx_radio_read16(bcm, 0x007A)
739 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
740 (bcm->board_type != 0x0416)) {
741 for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
742 bcm43xx_phy_write(bcm, offset,
743 (bcm43xx_phy_read(bcm, offset) + 0x2020)
747 bcm43xx_phy_write(bcm, 0x0035,
748 (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
750 if (radio->version == 0x2050)
751 bcm43xx_phy_write(bcm, 0x0038, 0x0667);
753 if (phy->connected) {
754 if (radio->version == 0x2050) {
755 bcm43xx_radio_write16(bcm, 0x007A,
756 bcm43xx_radio_read16(bcm, 0x007A)
758 bcm43xx_radio_write16(bcm, 0x0051,
759 bcm43xx_radio_read16(bcm, 0x0051)
762 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
764 bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
765 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
767 bcm43xx_phy_write(bcm, 0x001C, 0x186A);
769 bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
770 bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
771 bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
774 if (bcm->bad_frames_preempt) {
775 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
776 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
779 if (phy->version == 1 && radio->version == 0x2050) {
780 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
781 bcm43xx_phy_write(bcm, 0x0021, 0x3763);
782 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
783 bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
784 bcm43xx_phy_write(bcm, 0x0024, 0x037E);
786 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
787 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
788 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
790 if (phy->version == 1 && radio->version == 0x2050)
791 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
793 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
795 if (phy->version == 0)
796 bcm43xx_write16(bcm, 0x03E4, 0x3000);
798 /* Force to channel 7, even if not supported. */
799 bcm43xx_radio_selectchannel(bcm, 7, 0);
801 if (radio->version != 0x2050) {
802 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
803 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
806 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
807 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
809 if (radio->version == 0x2050) {
810 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
811 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
814 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
815 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
817 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
819 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
821 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
822 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
823 bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
825 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
827 if (radio->version == 0x2050)
828 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
830 bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
833 static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
835 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
836 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
839 bcm43xx_phy_write(bcm, 0x003E, 0x817A);
840 bcm43xx_radio_write16(bcm, 0x007A,
841 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
842 if ((radio->manufact == 0x17F) &&
843 (radio->version == 0x2050) &&
844 (radio->revision == 3 ||
845 radio->revision == 4 ||
846 radio->revision == 5)) {
847 bcm43xx_radio_write16(bcm, 0x0051, 0x001F);
848 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
849 bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
850 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
851 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
852 bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
853 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
854 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
855 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
857 if ((radio->manufact == 0x17F) &&
858 (radio->version == 0x2050) &&
859 (radio->revision == 6)) {
860 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
861 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
862 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
863 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
864 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
865 bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
866 bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
867 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
868 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
869 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
870 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
871 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
873 if ((radio->manufact == 0x17F) &&
874 (radio->version == 0x2050) &&
875 (radio->revision == 7)) {
876 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
877 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
878 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
879 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
880 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
881 bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
882 bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
883 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
884 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
885 bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
886 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
887 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
888 bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
890 if ((radio->manufact == 0x17F) &&
891 (radio->version == 0x2050) &&
892 (radio->revision == 8)) {
893 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
894 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
895 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
896 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
897 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
898 bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
899 bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
900 if (bcm->sprom.boardflags & 0x8000) {
901 bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
902 bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
904 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
905 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
907 bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
908 bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
909 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
910 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
913 for (offset = 0x0088; offset < 0x0098; offset++) {
914 bcm43xx_phy_write(bcm, offset, val);
918 for (offset = 0x0098; offset < 0x00A8; offset++) {
919 bcm43xx_phy_write(bcm, offset, val);
923 for (offset = 0x00A8; offset < 0x00C8; offset++) {
924 bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
927 if (phy->type == BCM43xx_PHYTYPE_G) {
928 bcm43xx_radio_write16(bcm, 0x007A,
929 bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
930 bcm43xx_radio_write16(bcm, 0x0051,
931 bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
932 bcm43xx_phy_write(bcm, 0x0802,
933 bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
934 bcm43xx_phy_write(bcm, 0x042B,
935 bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
938 /* Force to channel 7, even if not supported. */
939 bcm43xx_radio_selectchannel(bcm, 7, 0);
941 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
942 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
944 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002));
945 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
946 if (radio->manufact == 0x17F &&
947 radio->version == 0x2050 &&
948 radio->revision <= 2) {
949 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
950 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
951 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
952 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
954 bcm43xx_radio_write16(bcm, 0x007A,
955 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
957 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
959 bcm43xx_phy_write(bcm, 0x0014, 0x0200);
960 if (radio->version == 0x2050){
961 if (radio->revision == 3 ||
962 radio->revision == 4 ||
963 radio->revision == 5)
964 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
966 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
968 bcm43xx_phy_write(bcm, 0x0038, 0x0668);
969 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
970 if (radio->version == 0x2050) {
971 if (radio->revision == 3 ||
972 radio->revision == 4 ||
973 radio->revision == 5)
974 bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
975 else if (radio->revision <= 2)
976 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
980 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
982 bcm43xx_write16(bcm, 0x03E4, 0x0009);
983 if (phy->type == BCM43xx_PHYTYPE_B) {
984 bcm43xx_write16(bcm, 0x03E6, 0x8140);
985 bcm43xx_phy_write(bcm, 0x0016, 0x0410);
986 bcm43xx_phy_write(bcm, 0x0017, 0x0820);
987 bcm43xx_phy_write(bcm, 0x0062, 0x0007);
988 (void) bcm43xx_radio_calibrationvalue(bcm);
989 bcm43xx_phy_lo_b_measure(bcm);
990 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
991 bcm43xx_calc_nrssi_slope(bcm);
992 bcm43xx_calc_nrssi_threshold(bcm);
994 bcm43xx_phy_init_pctl(bcm);
996 bcm43xx_write16(bcm, 0x03E6, 0x0);
999 static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
1001 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1002 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1004 u16 backup_radio[3];
1007 u16 loop1_cnt, loop1_done, loop1_omitted;
1010 backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
1011 backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
1012 backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
1013 backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
1014 backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
1015 backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
1016 backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
1017 backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
1018 backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
1019 backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
1020 backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
1021 backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
1022 backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
1023 backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
1024 backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
1025 bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
1026 backup_bband = radio->baseband_atten;
1027 backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
1028 backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
1029 backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
1031 bcm43xx_phy_write(bcm, 0x0429,
1032 bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
1033 bcm43xx_phy_write(bcm, 0x0001,
1034 bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
1035 bcm43xx_phy_write(bcm, 0x0811,
1036 bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
1037 bcm43xx_phy_write(bcm, 0x0812,
1038 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
1039 bcm43xx_phy_write(bcm, 0x0811,
1040 bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
1041 bcm43xx_phy_write(bcm, 0x0812,
1042 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
1043 bcm43xx_phy_write(bcm, 0x0814,
1044 bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
1045 bcm43xx_phy_write(bcm, 0x0815,
1046 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
1047 bcm43xx_phy_write(bcm, 0x0814,
1048 bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
1049 bcm43xx_phy_write(bcm, 0x0815,
1050 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
1051 bcm43xx_phy_write(bcm, 0x0811,
1052 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
1053 bcm43xx_phy_write(bcm, 0x0812,
1054 bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
1056 bcm43xx_phy_write(bcm, 0x0811,
1057 (bcm43xx_phy_read(bcm, 0x0811)
1058 & 0xFFCF) | 0x0030);
1059 bcm43xx_phy_write(bcm, 0x0812,
1060 (bcm43xx_phy_read(bcm, 0x0812)
1061 & 0xFFCF) | 0x0010);
1063 bcm43xx_phy_write(bcm, 0x005A, 0x0780);
1064 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1065 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1066 if (phy->version == 0) {
1067 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
1069 bcm43xx_phy_write(bcm, 0x000A,
1070 bcm43xx_phy_read(bcm, 0x000A)
1073 bcm43xx_phy_write(bcm, 0x0814,
1074 bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
1075 bcm43xx_phy_write(bcm, 0x0815,
1076 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
1077 bcm43xx_phy_write(bcm, 0x0003,
1078 (bcm43xx_phy_read(bcm, 0x0003)
1079 & 0xFF9F) | 0x0040);
1080 if (radio->version == 0x2050 && radio->revision == 2) {
1081 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1082 bcm43xx_radio_write16(bcm, 0x0043,
1083 (bcm43xx_radio_read16(bcm, 0x0043)
1084 & 0xFFF0) | 0x0009);
1086 } else if (radio->revision == 8) {
1087 bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
1092 bcm43xx_phy_set_baseband_attenuation(bcm, 11);
1095 bcm43xx_phy_write(bcm, 0x080F, 0xC020);
1097 bcm43xx_phy_write(bcm, 0x080F, 0x8020);
1098 bcm43xx_phy_write(bcm, 0x0810, 0x0000);
1100 bcm43xx_phy_write(bcm, 0x002B,
1101 (bcm43xx_phy_read(bcm, 0x002B)
1102 & 0xFFC0) | 0x0001);
1103 bcm43xx_phy_write(bcm, 0x002B,
1104 (bcm43xx_phy_read(bcm, 0x002B)
1105 & 0xC0FF) | 0x0800);
1106 bcm43xx_phy_write(bcm, 0x0811,
1107 bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
1108 bcm43xx_phy_write(bcm, 0x0812,
1109 bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
1110 if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
1111 if (phy->rev >= 7) {
1112 bcm43xx_phy_write(bcm, 0x0811,
1113 bcm43xx_phy_read(bcm, 0x0811)
1115 bcm43xx_phy_write(bcm, 0x0812,
1116 bcm43xx_phy_read(bcm, 0x0812)
1120 bcm43xx_radio_write16(bcm, 0x007A,
1121 bcm43xx_radio_read16(bcm, 0x007A)
1124 for (i = 0; i < loop1_cnt; i++) {
1125 bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
1126 bcm43xx_phy_write(bcm, 0x0812,
1127 (bcm43xx_phy_read(bcm, 0x0812)
1128 & 0xF0FF) | (i << 8));
1129 bcm43xx_phy_write(bcm, 0x0015,
1130 (bcm43xx_phy_read(bcm, 0x0015)
1131 & 0x0FFF) | 0xA000);
1132 bcm43xx_phy_write(bcm, 0x0015,
1133 (bcm43xx_phy_read(bcm, 0x0015)
1134 & 0x0FFF) | 0xF000);
1136 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1140 loop1_omitted = loop1_cnt - loop1_done;
1143 if (loop1_done >= 8) {
1144 bcm43xx_phy_write(bcm, 0x0812,
1145 bcm43xx_phy_read(bcm, 0x0812)
1147 for (i = loop1_done - 8; i < 16; i++) {
1148 bcm43xx_phy_write(bcm, 0x0812,
1149 (bcm43xx_phy_read(bcm, 0x0812)
1150 & 0xF0FF) | (i << 8));
1151 bcm43xx_phy_write(bcm, 0x0015,
1152 (bcm43xx_phy_read(bcm, 0x0015)
1153 & 0x0FFF) | 0xA000);
1154 bcm43xx_phy_write(bcm, 0x0015,
1155 (bcm43xx_phy_read(bcm, 0x0015)
1156 & 0x0FFF) | 0xF000);
1158 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1163 bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
1164 bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
1165 bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
1166 bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
1167 bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
1168 bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
1169 bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
1170 bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
1171 bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
1172 bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
1173 bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
1175 bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
1177 bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
1178 bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
1179 bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
1181 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
1183 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
1184 bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
1185 bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
1186 bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
1188 phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
1189 phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
1192 static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1194 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1195 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1199 bcm43xx_phy_initb5(bcm);
1200 else if (phy->rev >= 2 && phy->rev <= 7)
1201 bcm43xx_phy_initb6(bcm);
1202 if (phy->rev >= 2 || phy->connected)
1203 bcm43xx_phy_inita(bcm);
1205 if (phy->rev >= 2) {
1206 bcm43xx_phy_write(bcm, 0x0814, 0x0000);
1207 bcm43xx_phy_write(bcm, 0x0815, 0x0000);
1209 bcm43xx_phy_write(bcm, 0x0811, 0x0000);
1210 else if (phy->rev >= 3)
1211 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1212 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1213 if (phy->connected) {
1214 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
1216 bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
1217 bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
1219 bcm43xx_phy_write(bcm, 0x04CC,
1220 (bcm43xx_phy_read(bcm, 0x04CC)
1221 & 0x00FF) | 0x1F00);
1226 if (phy->rev < 3 && phy->connected)
1227 bcm43xx_phy_write(bcm, 0x047E, 0x0078);
1228 if (phy->rev >= 6 && phy->rev <= 8) {
1229 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
1230 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
1232 if (phy->rev >= 2 && phy->connected)
1233 bcm43xx_calc_loopback_gain(bcm);
1234 if (radio->revision != 8) {
1235 if (radio->initval == 0xFFFF)
1236 radio->initval = bcm43xx_radio_init2050(bcm);
1238 bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
1240 if (radio->txctl2 == 0xFFFF) {
1241 bcm43xx_phy_lo_g_measure(bcm);
1243 if (radio->version == 0x2050 && radio->revision == 8) {
1246 bcm43xx_radio_write16(bcm, 0x0052,
1247 (bcm43xx_radio_read16(bcm, 0x0052)
1248 & 0xFFF0) | radio->txctl1);
1250 if (phy->rev >= 6) {
1252 bcm43xx_phy_write(bcm, 0x0036,
1253 (bcm43xx_phy_read(bcm, 0x0036)
1254 & 0xF000) | (FIXME << 12));
1257 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
1258 bcm43xx_phy_write(bcm, 0x002E, 0x8075);
1260 bcm43xx_phy_write(bcm, 0x003E, 0x807F);
1262 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1264 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1266 if (phy->connected) {
1267 bcm43xx_phy_lo_adjust(bcm, 0);
1268 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1271 if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
1272 /* The specs state to update the NRSSI LT with
1273 * the value 0x7FFFFFFF here. I think that is some weird
1274 * compiler optimization in the original driver.
1275 * Essentially, what we do here is resetting all NRSSI LT
1276 * entries to -32 (see the limit_value() in nrssi_hw_update())
1278 bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
1279 bcm43xx_calc_nrssi_threshold(bcm);
1280 } else if (phy->connected) {
1281 if (radio->nrssi[0] == -1000) {
1282 assert(radio->nrssi[1] == -1000);
1283 bcm43xx_calc_nrssi_slope(bcm);
1285 assert(radio->nrssi[1] != -1000);
1286 bcm43xx_calc_nrssi_threshold(bcm);
1289 if (radio->revision == 8)
1290 bcm43xx_phy_write(bcm, 0x0805, 0x3230);
1291 bcm43xx_phy_init_pctl(bcm);
1292 if (bcm->chip_id == 0x4306 && bcm->chip_package == 2) {
1293 bcm43xx_phy_write(bcm, 0x0429,
1294 bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
1295 bcm43xx_phy_write(bcm, 0x04C3,
1296 bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
1300 static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
1304 unsigned long flags;
1306 local_irq_save(flags);
1307 for (i = 0; i < 10; i++){
1308 bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
1310 bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
1312 bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
1314 ret += bcm43xx_phy_read(bcm, 0x002C);
1316 local_irq_restore(flags);
1317 bcm43xx_voluntary_preempt();
1322 void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
1324 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1325 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1326 u16 regstack[12] = { 0 };
1331 regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
1332 regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
1334 if (radio->version == 0x2053) {
1335 regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
1336 regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
1337 regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
1338 regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
1339 regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
1340 regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
1342 regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
1343 regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
1344 regstack[10] = bcm43xx_read16(bcm, 0x03EC);
1345 regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
1347 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
1348 bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
1349 bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
1350 bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
1352 bcm43xx_phy_write(bcm, 0x0015, 0xB000);
1353 bcm43xx_phy_write(bcm, 0x002B, 0x0004);
1355 if (radio->version == 0x2053) {
1356 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1357 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1360 phy->minlowsig[0] = 0xFFFF;
1362 for (i = 0; i < 4; i++) {
1363 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1364 bcm43xx_phy_lo_b_r15_loop(bcm);
1366 for (i = 0; i < 10; i++) {
1367 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1368 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1369 if (mls < phy->minlowsig[0]) {
1370 phy->minlowsig[0] = mls;
1371 phy->minlowsigpos[0] = i;
1374 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
1376 phy->minlowsig[1] = 0xFFFF;
1378 for (i = -4; i < 5; i += 2) {
1379 for (j = -4; j < 5; j += 2) {
1381 fval = (0x0100 * i) + j + 0x0100;
1383 fval = (0x0100 * i) + j;
1384 bcm43xx_phy_write(bcm, 0x002F, fval);
1385 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1386 if (mls < phy->minlowsig[1]) {
1387 phy->minlowsig[1] = mls;
1388 phy->minlowsigpos[1] = fval;
1392 phy->minlowsigpos[1] += 0x0101;
1394 bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
1395 if (radio->version == 0x2053) {
1396 bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
1397 bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
1398 bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
1399 bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
1400 bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
1401 bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
1403 bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
1404 bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
1406 bcm43xx_radio_write16(bcm, 0x0052,
1407 (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
1410 bcm43xx_write16(bcm, 0x03EC, regstack[10]);
1412 bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
1416 u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
1418 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1420 unsigned long flags;
1422 local_irq_save(flags);
1423 if (phy->connected) {
1424 bcm43xx_phy_write(bcm, 0x15, 0xE300);
1426 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
1428 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
1430 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
1432 bcm43xx_phy_write(bcm, 0x0015, 0xF300);
1435 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
1437 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
1439 bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
1442 ret = bcm43xx_phy_read(bcm, 0x002D);
1443 local_irq_restore(flags);
1444 bcm43xx_voluntary_preempt();
1449 static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
1454 for (i = 0; i < 8; i++)
1455 ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
1460 /* Write the LocalOscillator CONTROL */
1462 void bcm43xx_lo_write(struct bcm43xx_private *bcm,
1463 struct bcm43xx_lopair *pair)
1467 value = (u8)(pair->low);
1468 value |= ((u8)(pair->high)) << 8;
1470 #ifdef CONFIG_BCM43XX_DEBUG
1472 if (pair->low < -8 || pair->low > 8 ||
1473 pair->high < -8 || pair->high > 8) {
1474 printk(KERN_WARNING PFX
1475 "WARNING: Writing invalid LOpair "
1476 "(low: %d, high: %d, index: %lu)\n",
1477 pair->low, pair->high,
1478 (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
1483 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
1487 struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
1488 u16 baseband_attenuation,
1489 u16 radio_attenuation,
1492 static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
1493 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1495 if (baseband_attenuation > 6)
1496 baseband_attenuation = 6;
1497 assert(radio_attenuation < 10);
1500 return bcm43xx_get_lopair(phy,
1502 baseband_attenuation);
1504 return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
1508 struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
1510 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1512 return bcm43xx_find_lopair(bcm,
1513 radio->baseband_atten,
1519 void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
1521 struct bcm43xx_lopair *pair;
1524 /* Use fixed values. Only for initialization. */
1525 pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
1527 pair = bcm43xx_current_lopair(bcm);
1528 bcm43xx_lo_write(bcm, pair);
1531 static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
1533 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1537 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1539 smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1540 for (i = 0; i < 16; i++) {
1541 bcm43xx_radio_write16(bcm, 0x0052, i);
1543 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1544 if (tmp < smallest) {
1549 radio->txctl2 = txctl2;
1553 void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
1554 const struct bcm43xx_lopair *in_pair,
1555 struct bcm43xx_lopair *out_pair,
1558 static const struct bcm43xx_lopair transitions[8] = {
1559 { .high = 1, .low = 1, },
1560 { .high = 1, .low = 0, },
1561 { .high = 1, .low = -1, },
1562 { .high = 0, .low = -1, },
1563 { .high = -1, .low = -1, },
1564 { .high = -1, .low = 0, },
1565 { .high = -1, .low = 1, },
1566 { .high = 0, .low = 1, },
1568 struct bcm43xx_lopair lowest_transition = {
1569 .high = in_pair->high,
1570 .low = in_pair->low,
1572 struct bcm43xx_lopair tmp_pair;
1573 struct bcm43xx_lopair transition;
1578 u32 lowest_deviation;
1581 /* Note that in_pair and out_pair can point to the same pair. Be careful. */
1583 bcm43xx_lo_write(bcm, &lowest_transition);
1584 lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1587 assert(state >= 0 && state <= 8);
1591 } else if (state % 2 == 0) {
1604 tmp_pair.high = lowest_transition.high;
1605 tmp_pair.low = lowest_transition.low;
1607 assert(j >= 1 && j <= 8);
1608 transition.high = tmp_pair.high + transitions[j - 1].high;
1609 transition.low = tmp_pair.low + transitions[j - 1].low;
1610 if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
1611 bcm43xx_lo_write(bcm, &transition);
1612 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1613 if (tmp < lowest_deviation) {
1614 lowest_deviation = tmp;
1618 lowest_transition.high = transition.high;
1619 lowest_transition.low = transition.low;
1629 } while (i-- && found_lower);
1631 out_pair->high = lowest_transition.high;
1632 out_pair->low = lowest_transition.low;
1635 /* Set the baseband attenuation value on chip. */
1636 void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
1637 u16 baseband_attenuation)
1639 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1642 if (phy->version == 0) {
1643 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
1644 value |= (baseband_attenuation & 0x000F);
1645 bcm43xx_write16(bcm, 0x03E6, value);
1649 if (phy->version > 1) {
1650 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
1651 value |= (baseband_attenuation << 2) & 0x003C;
1653 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
1654 value |= (baseband_attenuation << 3) & 0x0078;
1656 bcm43xx_phy_write(bcm, 0x0060, value);
1659 /* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
1660 void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
1662 static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
1663 const int is_initializing = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZING);
1664 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1665 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1666 u16 h, i, oldi = 0, j;
1667 struct bcm43xx_lopair control;
1668 struct bcm43xx_lopair *tmp_control;
1670 u16 regstack[16] = { 0 };
1673 //XXX: What are these?
1676 oldchannel = radio->channel;
1678 if (phy->connected) {
1679 regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
1680 regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
1681 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1682 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1684 regstack[3] = bcm43xx_read16(bcm, 0x03E2);
1685 bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
1686 regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1687 regstack[5] = bcm43xx_phy_read(bcm, 0x15);
1688 regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
1689 regstack[7] = bcm43xx_phy_read(bcm, 0x35);
1690 regstack[8] = bcm43xx_phy_read(bcm, 0x60);
1691 regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
1692 regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
1693 regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
1694 if (phy->connected) {
1695 regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
1696 regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
1697 regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
1698 regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
1700 bcm43xx_radio_selectchannel(bcm, 6, 0);
1701 if (phy->connected) {
1702 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1703 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1704 bcm43xx_dummy_transmission(bcm);
1706 bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
1708 bcm43xx_phy_set_baseband_attenuation(bcm, 2);
1710 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
1711 bcm43xx_phy_write(bcm, 0x002E, 0x007F);
1712 bcm43xx_phy_write(bcm, 0x080F, 0x0078);
1713 bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
1714 bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
1715 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1716 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1717 if (phy->connected) {
1718 bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
1719 bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
1720 bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
1721 bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
1723 if (is_initializing)
1724 bcm43xx_phy_lo_g_measure_txctl2(bcm);
1725 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1730 for (h = 0; h < 10; h++) {
1731 /* Loop over each possible RadioAttenuation (0-9) */
1733 if (is_initializing) {
1737 } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
1738 ((i % 2 == 0) && (oldi % 2 == 0))) {
1739 tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
1740 memcpy(&control, tmp_control, sizeof(control));
1742 tmp_control = bcm43xx_get_lopair(phy, 3, 0);
1743 memcpy(&control, tmp_control, sizeof(control));
1746 /* Loop over each possible BasebandAttenuation/2 */
1747 for (j = 0; j < 4; j++) {
1748 if (is_initializing) {
1760 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1761 if (!tmp_control->used)
1763 memcpy(&control, tmp_control, sizeof(control));
1767 bcm43xx_radio_write16(bcm, 0x43, i);
1768 bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
1770 bcm43xx_voluntary_preempt();
1772 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1774 tmp = (regstack[10] & 0xFFF0);
1777 bcm43xx_radio_write16(bcm, 0x007A, tmp);
1779 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1780 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1784 /* Loop over each possible RadioAttenuation (10-13) */
1785 for (i = 10; i < 14; i++) {
1786 /* Loop over each possible BasebandAttenuation/2 */
1787 for (j = 0; j < 4; j++) {
1788 if (is_initializing) {
1789 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1790 memcpy(&control, tmp_control, sizeof(control));
1791 tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
1802 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1803 if (!tmp_control->used)
1805 memcpy(&control, tmp_control, sizeof(control));
1809 bcm43xx_radio_write16(bcm, 0x43, i - 9);
1810 bcm43xx_radio_write16(bcm, 0x52,
1812 | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
1814 bcm43xx_voluntary_preempt();
1816 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1818 tmp = (regstack[10] & 0xFFF0);
1821 bcm43xx_radio_write16(bcm, 0x7A, tmp);
1823 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1824 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1829 if (phy->connected) {
1830 bcm43xx_phy_write(bcm, 0x0015, 0xE300);
1831 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
1833 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
1835 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
1836 bcm43xx_voluntary_preempt();
1838 bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
1839 bcm43xx_phy_lo_adjust(bcm, is_initializing);
1840 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1842 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1844 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1845 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
1846 bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
1847 bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
1848 bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
1849 bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
1850 bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
1851 bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
1852 regstack[11] &= 0x00F0;
1853 regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
1854 bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
1855 bcm43xx_write16(bcm, 0x03E2, regstack[3]);
1856 if (phy->connected) {
1857 bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
1858 bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
1859 bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
1860 bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
1861 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
1862 bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
1864 bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
1866 #ifdef CONFIG_BCM43XX_DEBUG
1868 /* Sanity check for all lopairs. */
1869 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1870 tmp_control = phy->_lo_pairs + i;
1871 if (tmp_control->low < -8 || tmp_control->low > 8 ||
1872 tmp_control->high < -8 || tmp_control->high > 8) {
1873 printk(KERN_WARNING PFX
1874 "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
1875 tmp_control->low, tmp_control->high, i);
1879 #endif /* CONFIG_BCM43XX_DEBUG */
1883 void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
1885 struct bcm43xx_lopair *pair;
1887 pair = bcm43xx_current_lopair(bcm);
1891 void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
1893 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1894 struct bcm43xx_lopair *pair;
1897 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1898 pair = phy->_lo_pairs + i;
1903 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1904 * This function converts a TSSI value to dBm in Q5.2
1906 static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
1908 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1912 tmp = phy->idle_tssi;
1914 tmp -= phy->savedpctlreg;
1916 switch (phy->type) {
1917 case BCM43xx_PHYTYPE_A:
1919 tmp = limit_value(tmp, 0x00, 0xFF);
1920 dbm = phy->tssi2dbm[tmp];
1921 TODO(); //TODO: There's a FIXME on the specs
1923 case BCM43xx_PHYTYPE_B:
1924 case BCM43xx_PHYTYPE_G:
1925 tmp = limit_value(tmp, 0x00, 0x3F);
1926 dbm = phy->tssi2dbm[tmp];
1935 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1936 void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
1938 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1939 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1941 if (phy->savedpctlreg == 0xFFFF)
1943 if ((bcm->board_type == 0x0416) &&
1944 (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
1947 switch (phy->type) {
1948 case BCM43xx_PHYTYPE_A: {
1950 TODO(); //TODO: Nothing for A PHYs yet :-/
1954 case BCM43xx_PHYTYPE_B:
1955 case BCM43xx_PHYTYPE_G: {
1961 s16 desired_pwr, estimated_pwr, pwr_adjust;
1962 s16 radio_att_delta, baseband_att_delta;
1963 s16 radio_attenuation, baseband_attenuation;
1964 unsigned long phylock_flags;
1966 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
1967 v0 = (s8)(tmp & 0x00FF);
1968 v1 = (s8)((tmp & 0xFF00) >> 8);
1969 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
1970 v2 = (s8)(tmp & 0x00FF);
1971 v3 = (s8)((tmp & 0xFF00) >> 8);
1974 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
1975 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
1976 v0 = (s8)(tmp & 0x00FF);
1977 v1 = (s8)((tmp & 0xFF00) >> 8);
1978 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
1979 v2 = (s8)(tmp & 0x00FF);
1980 v3 = (s8)((tmp & 0xFF00) >> 8);
1981 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
1983 v0 = (v0 + 0x20) & 0x3F;
1984 v1 = (v1 + 0x20) & 0x3F;
1985 v2 = (v2 + 0x20) & 0x3F;
1986 v3 = (v3 + 0x20) & 0x3F;
1989 bcm43xx_radio_clear_tssi(bcm);
1991 average = (v0 + v1 + v2 + v3 + 2) / 4;
1993 if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
1996 estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
1998 max_pwr = bcm->sprom.maxpower_bgphy;
2000 if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
2001 (phy->type == BCM43xx_PHYTYPE_G))
2005 max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
2006 where REG is the max power as per the regulatory domain
2009 desired_pwr = limit_value(radio->txpower_desired, 0, max_pwr);
2010 /* Check if we need to adjust the current power. */
2011 pwr_adjust = desired_pwr - estimated_pwr;
2012 radio_att_delta = -(pwr_adjust + 7) >> 3;
2013 baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
2014 if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
2015 bcm43xx_phy_lo_mark_current_used(bcm);
2019 /* Calculate the new attenuation values. */
2020 baseband_attenuation = radio->baseband_atten;
2021 baseband_attenuation += baseband_att_delta;
2022 radio_attenuation = radio->radio_atten;
2023 radio_attenuation += radio_att_delta;
2025 /* Get baseband and radio attenuation values into their permitted ranges.
2026 * baseband 0-11, radio 0-9.
2027 * Radio attenuation affects power level 4 times as much as baseband.
2029 if (radio_attenuation < 0) {
2030 baseband_attenuation -= (4 * -radio_attenuation);
2031 radio_attenuation = 0;
2032 } else if (radio_attenuation > 9) {
2033 baseband_attenuation += (4 * (radio_attenuation - 9));
2034 radio_attenuation = 9;
2036 while (baseband_attenuation < 0 && radio_attenuation > 0) {
2037 baseband_attenuation += 4;
2038 radio_attenuation--;
2040 while (baseband_attenuation > 11 && radio_attenuation < 9) {
2041 baseband_attenuation -= 4;
2042 radio_attenuation++;
2045 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2047 txpower = radio->txctl1;
2048 if ((radio->version == 0x2050) && (radio->revision == 2)) {
2049 if (radio_attenuation <= 1) {
2052 radio_attenuation += 2;
2053 baseband_attenuation += 2;
2054 } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2055 baseband_attenuation += 4 * (radio_attenuation - 2);
2056 radio_attenuation = 2;
2058 } else if (radio_attenuation > 4 && txpower != 0) {
2060 if (baseband_attenuation < 3) {
2061 radio_attenuation -= 3;
2062 baseband_attenuation += 2;
2064 radio_attenuation -= 2;
2065 baseband_attenuation -= 2;
2069 radio->txctl1 = txpower;
2070 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2071 radio_attenuation = limit_value(radio_attenuation, 0, 9);
2073 bcm43xx_phy_lock(bcm, phylock_flags);
2074 bcm43xx_radio_lock(bcm);
2075 bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
2076 radio_attenuation, txpower);
2077 bcm43xx_phy_lo_mark_current_used(bcm);
2078 bcm43xx_radio_unlock(bcm);
2079 bcm43xx_phy_unlock(bcm, phylock_flags);
2088 s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
2093 return (num+den/2)/den;
2097 s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
2099 s32 m1, m2, f = 256, q, delta;
2102 m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2103 m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2107 q = bcm43xx_tssi2dbm_ad(f * 4096 -
2108 bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2112 } while (delta >= 2);
2113 entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2117 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2118 int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
2120 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2121 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2122 s16 pab0, pab1, pab2;
2126 if (phy->type == BCM43xx_PHYTYPE_A) {
2127 pab0 = (s16)(bcm->sprom.pa1b0);
2128 pab1 = (s16)(bcm->sprom.pa1b1);
2129 pab2 = (s16)(bcm->sprom.pa1b2);
2131 pab0 = (s16)(bcm->sprom.pa0b0);
2132 pab1 = (s16)(bcm->sprom.pa0b1);
2133 pab2 = (s16)(bcm->sprom.pa0b2);
2136 if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
2137 phy->idle_tssi = 0x34;
2138 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2142 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2143 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2144 /* The pabX values are set in SPROM. Use them. */
2145 if (phy->type == BCM43xx_PHYTYPE_A) {
2146 if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
2147 (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
2148 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
2150 phy->idle_tssi = 62;
2152 if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
2153 (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
2154 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
2156 phy->idle_tssi = 62;
2158 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2159 if (dyn_tssi2dbm == NULL) {
2160 printk(KERN_ERR PFX "Could not allocate memory"
2161 "for tssi2dbm table\n");
2164 for (idx = 0; idx < 64; idx++)
2165 if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2166 phy->tssi2dbm = NULL;
2167 printk(KERN_ERR PFX "Could not generate "
2168 "tssi2dBm table\n");
2169 kfree(dyn_tssi2dbm);
2172 phy->tssi2dbm = dyn_tssi2dbm;
2173 phy->dyn_tssi_tbl = 1;
2175 /* pabX values not set in SPROM. */
2176 switch (phy->type) {
2177 case BCM43xx_PHYTYPE_A:
2178 /* APHY needs a generated table. */
2179 phy->tssi2dbm = NULL;
2180 printk(KERN_ERR PFX "Could not generate tssi2dBm "
2181 "table (wrong SPROM info)!\n");
2183 case BCM43xx_PHYTYPE_B:
2184 phy->idle_tssi = 0x34;
2185 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2187 case BCM43xx_PHYTYPE_G:
2188 phy->idle_tssi = 0x34;
2189 phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
2197 int bcm43xx_phy_init(struct bcm43xx_private *bcm)
2199 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2202 switch (phy->type) {
2203 case BCM43xx_PHYTYPE_A:
2204 if (phy->rev == 2 || phy->rev == 3) {
2205 bcm43xx_phy_inita(bcm);
2209 case BCM43xx_PHYTYPE_B:
2212 bcm43xx_phy_initb2(bcm);
2216 bcm43xx_phy_initb4(bcm);
2220 bcm43xx_phy_initb5(bcm);
2224 bcm43xx_phy_initb6(bcm);
2229 case BCM43xx_PHYTYPE_G:
2230 bcm43xx_phy_initg(bcm);
2235 printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
2240 void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
2242 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2248 antennadiv = phy->antenna_diversity;
2250 if (antennadiv == 0xFFFF)
2252 assert(antennadiv <= 3);
2254 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2255 BCM43xx_UCODEFLAGS_OFFSET);
2256 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2257 BCM43xx_UCODEFLAGS_OFFSET,
2258 ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
2260 switch (phy->type) {
2261 case BCM43xx_PHYTYPE_A:
2262 case BCM43xx_PHYTYPE_G:
2263 if (phy->type == BCM43xx_PHYTYPE_A)
2268 if (antennadiv == 2)
2269 value = (3/*automatic*/ << 7);
2271 value = (antennadiv << 7);
2272 bcm43xx_phy_write(bcm, offset + 1,
2273 (bcm43xx_phy_read(bcm, offset + 1)
2276 if (antennadiv >= 2) {
2277 if (antennadiv == 2)
2278 value = (antennadiv << 7);
2280 value = (0/*force0*/ << 7);
2281 bcm43xx_phy_write(bcm, offset + 0x2B,
2282 (bcm43xx_phy_read(bcm, offset + 0x2B)
2286 if (phy->type == BCM43xx_PHYTYPE_G) {
2287 if (antennadiv >= 2)
2288 bcm43xx_phy_write(bcm, 0x048C,
2289 bcm43xx_phy_read(bcm, 0x048C)
2292 bcm43xx_phy_write(bcm, 0x048C,
2293 bcm43xx_phy_read(bcm, 0x048C)
2295 if (phy->rev >= 2) {
2296 bcm43xx_phy_write(bcm, 0x0461,
2297 bcm43xx_phy_read(bcm, 0x0461)
2299 bcm43xx_phy_write(bcm, 0x04AD,
2300 (bcm43xx_phy_read(bcm, 0x04AD)
2301 & 0x00FF) | 0x0015);
2303 bcm43xx_phy_write(bcm, 0x0427, 0x0008);
2305 bcm43xx_phy_write(bcm, 0x0427,
2306 (bcm43xx_phy_read(bcm, 0x0427)
2307 & 0x00FF) | 0x0008);
2309 else if (phy->rev >= 6)
2310 bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
2313 bcm43xx_phy_write(bcm, 0x002B,
2314 (bcm43xx_phy_read(bcm, 0x002B)
2315 & 0x00FF) | 0x0024);
2317 bcm43xx_phy_write(bcm, 0x0061,
2318 bcm43xx_phy_read(bcm, 0x0061)
2320 if (phy->rev == 3) {
2321 bcm43xx_phy_write(bcm, 0x0093, 0x001D);
2322 bcm43xx_phy_write(bcm, 0x0027, 0x0008);
2324 bcm43xx_phy_write(bcm, 0x0093, 0x003A);
2325 bcm43xx_phy_write(bcm, 0x0027,
2326 (bcm43xx_phy_read(bcm, 0x0027)
2327 & 0x00FF) | 0x0008);
2332 case BCM43xx_PHYTYPE_B:
2333 if (bcm->current_core->rev == 2)
2334 value = (3/*automatic*/ << 7);
2336 value = (antennadiv << 7);
2337 bcm43xx_phy_write(bcm, 0x03E2,
2338 (bcm43xx_phy_read(bcm, 0x03E2)
2345 if (antennadiv >= 2) {
2346 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2347 BCM43xx_UCODEFLAGS_OFFSET);
2348 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2349 BCM43xx_UCODEFLAGS_OFFSET,
2350 ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
2353 phy->antenna_diversity = antennadiv;