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);
84 void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
86 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
88 assert(irqs_disabled());
89 if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
93 if (bcm->current_core->rev < 3) {
94 bcm43xx_mac_suspend(bcm);
95 spin_lock(&phy->lock);
97 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
98 bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
103 void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
105 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
107 assert(irqs_disabled());
108 if (bcm->current_core->rev < 3) {
109 if (phy->is_locked) {
110 spin_unlock(&phy->lock);
111 bcm43xx_mac_enable(bcm);
114 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
115 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
120 u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
122 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
123 return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
126 void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
128 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
130 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
133 void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
135 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
138 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
141 if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
142 /* We do not want to be preempted while calibrating
145 local_irq_save(flags);
147 bcm43xx_wireless_core_reset(bcm, 0);
148 bcm43xx_phy_initg(bcm);
149 bcm43xx_wireless_core_reset(bcm, 1);
151 local_irq_restore(flags);
157 * http://bcm-specs.sipsolutions.net/SetPHY
159 int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
161 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
164 if (bcm->current_core->rev < 5)
167 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
169 if (!(flags & 0x00010000))
171 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
172 flags |= (0x800 << 18);
173 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
175 if (!(flags & 0x00020000))
177 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
178 flags &= ~(0x800 << 18);
179 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
182 phy->connected = connect;
184 dprintk(KERN_INFO PFX "PHY connected\n");
186 dprintk(KERN_INFO PFX "PHY disconnected\n");
191 /* intialize B PHY power control
192 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
194 static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
196 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
197 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
198 u16 saved_batt = 0, saved_ratt = 0, saved_txctl1 = 0;
199 int must_reset_txpower = 0;
201 assert(phy->type != BCM43xx_PHYTYPE_A);
202 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
203 (bcm->board_type == 0x0416))
206 bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
207 bcm43xx_phy_write(bcm, 0x0028, 0x8018);
209 if (phy->type == BCM43xx_PHYTYPE_G) {
212 bcm43xx_phy_write(bcm, 0x047A, 0xC111);
214 if (phy->savedpctlreg != 0xFFFF)
217 if (phy->type == BCM43xx_PHYTYPE_B &&
219 radio->version == 0x2050) {
220 bcm43xx_radio_write16(bcm, 0x0076,
221 bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
223 saved_batt = radio->baseband_atten;
224 saved_ratt = radio->radio_atten;
225 saved_txctl1 = radio->txctl1;
226 if ((radio->revision >= 6) && (radio->revision <= 8)
227 && /*FIXME: incomplete specs for 5 < revision < 9 */ 0)
228 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 0x1F, 0);
230 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
231 must_reset_txpower = 1;
233 bcm43xx_dummy_transmission(bcm);
235 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
237 if (must_reset_txpower)
238 bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
240 bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
241 bcm43xx_radio_clear_tssi(bcm);
244 static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
246 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
252 bcm43xx_ilt_write(bcm, offset, 0x00FE);
253 bcm43xx_ilt_write(bcm, offset + 1, 0x000D);
254 bcm43xx_ilt_write(bcm, offset + 2, 0x0013);
255 bcm43xx_ilt_write(bcm, offset + 3, 0x0019);
258 bcm43xx_ilt_write(bcm, 0x1800, 0x2710);
259 bcm43xx_ilt_write(bcm, 0x1801, 0x9B83);
260 bcm43xx_ilt_write(bcm, 0x1802, 0x9B83);
261 bcm43xx_ilt_write(bcm, 0x1803, 0x0F8D);
262 bcm43xx_phy_write(bcm, 0x0455, 0x0004);
265 bcm43xx_phy_write(bcm, 0x04A5, (bcm43xx_phy_read(bcm, 0x04A5) & 0x00FF) | 0x5700);
266 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xFF80) | 0x000F);
267 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xC07F) | 0x2B80);
268 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xF0FF) | 0x0300);
270 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
272 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xFFF0) | 0x0008);
273 bcm43xx_phy_write(bcm, 0x04A1, (bcm43xx_phy_read(bcm, 0x04A1) & 0xF0FF) | 0x0600);
274 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xF0FF) | 0x0700);
275 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xF0FF) | 0x0100);
278 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
280 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xFF00) | 0x001C);
281 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xC0FF) | 0x0200);
282 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0xFF00) | 0x001C);
283 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xFF00) | 0x0020);
284 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xC0FF) | 0x0200);
285 bcm43xx_phy_write(bcm, 0x0482, (bcm43xx_phy_read(bcm, 0x0482) & 0xFF00) | 0x002E);
286 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0x00FF) | 0x1A00);
287 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0xFF00) | 0x0028);
288 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0x00FF) | 0x2C00);
291 bcm43xx_phy_write(bcm, 0x0430, 0x092B);
292 bcm43xx_phy_write(bcm, 0x041B, (bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1) | 0x0002);
294 bcm43xx_phy_write(bcm, 0x041B, bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1);
295 bcm43xx_phy_write(bcm, 0x041F, 0x287A);
296 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0xFFF0) | 0x0004);
300 bcm43xx_phy_write(bcm, 0x0422, 0x287A);
301 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0x0FFF) | 0x3000);
304 bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
305 bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
308 bcm43xx_phy_write(bcm, 0x04AB, (bcm43xx_phy_read(bcm, 0x04AB) & 0xF0FF) | 0x0600);
309 bcm43xx_phy_write(bcm, 0x048B, 0x005E);
310 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xFF00) | 0x001E);
311 bcm43xx_phy_write(bcm, 0x048D, 0x0002);
314 bcm43xx_ilt_write(bcm, offset + 0x0800, 0);
315 bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
316 bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
317 bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
320 static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
322 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
325 assert(phy->type == BCM43xx_PHYTYPE_G);
327 bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
328 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
329 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
330 bcm43xx_phy_write(bcm, 0x042C, 0x005A);
331 bcm43xx_phy_write(bcm, 0x0427, 0x001A);
333 for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
334 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
335 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
336 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
337 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
338 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
340 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
341 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
344 bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
345 bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
346 } else if (phy->rev > 2) {
347 bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
348 bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
349 bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
351 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
353 for (i = 0; i < 64; i++)
354 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
355 for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
356 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
360 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
361 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
362 else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
363 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
364 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
366 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
367 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
370 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
371 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
372 else if ((phy->rev > 2) && (phy->rev <= 7))
373 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
374 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
377 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
378 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
379 for (i = 0; i < 4; i++) {
380 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
381 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
382 bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
383 bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
385 bcm43xx_phy_agcsetup(bcm);
387 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
388 (bcm->board_type == 0x0416) &&
389 (bcm->board_revision == 0x0017))
392 bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
393 bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
395 for (i = 0; i <= 0x2F; i++)
396 bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
397 bcm43xx_phy_agcsetup(bcm);
398 bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
399 bcm43xx_phy_write(bcm, 0x0403, 0x1000);
400 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
401 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
403 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
404 (bcm->board_type == 0x0416) &&
405 (bcm->board_revision == 0x0017))
408 bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
409 bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
413 /* Initialize the noisescaletable for APHY */
414 static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
416 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
419 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
420 for (i = 0; i < 12; i++) {
422 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
424 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
427 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
429 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
430 for (i = 0; i < 11; i++) {
432 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
434 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
437 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
439 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
442 static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
444 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
447 assert(phy->type == BCM43xx_PHYTYPE_A);
450 bcm43xx_phy_write(bcm, 0x008E, 0x3800);
451 bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
452 bcm43xx_phy_write(bcm, 0x0036, 0x0400);
454 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
456 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
457 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
458 bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
459 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
461 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
462 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
463 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
464 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
466 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
467 bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
468 bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
470 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
471 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
472 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
473 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
474 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
476 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
477 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
478 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
479 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
480 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
481 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
482 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
484 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
485 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
486 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
488 for (i = 0; i < 16; i++)
489 bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
491 bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
492 bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
493 bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
494 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
496 for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
497 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
498 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
499 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
500 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
501 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
502 bcm43xx_phy_init_noisescaletbl(bcm);
503 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
504 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
507 for (i = 0; i < 64; i++)
508 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
510 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
512 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
513 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
514 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
516 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
517 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
518 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
519 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
520 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
522 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
523 for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
524 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
525 bcm43xx_phy_init_noisescaletbl(bcm);
526 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
527 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
529 bcm43xx_phy_write(bcm, 0x0003, 0x1808);
531 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
532 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
533 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
534 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
535 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
537 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
538 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
539 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
540 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
541 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
542 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
543 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
545 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
546 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
547 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
549 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
550 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
557 /* Initialize APHY. This is also called for the GPHY in some cases. */
558 static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
560 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
561 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
564 if (phy->type == BCM43xx_PHYTYPE_A) {
565 bcm43xx_phy_setupa(bcm);
567 bcm43xx_phy_setupg(bcm);
568 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
569 bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
573 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
574 (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
575 bcm43xx_phy_write(bcm, 0x0034, 0x0001);
577 TODO();//TODO: RSSI AGC
578 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
579 bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
580 bcm43xx_radio_init2060(bcm);
582 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
583 && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
584 if (radio->lofcal == 0xFFFF) {
585 TODO();//TODO: LOF Cal
586 bcm43xx_radio_set_tx_iq(bcm);
588 bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
591 bcm43xx_phy_write(bcm, 0x007A, 0xF111);
593 if (phy->savedpctlreg == 0xFFFF) {
594 bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
595 bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
597 tval = bcm43xx_ilt_read(bcm, 0x3001);
599 bcm43xx_ilt_write(bcm, 0x3001,
600 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
603 bcm43xx_ilt_write(bcm, 0x3001,
604 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
607 bcm43xx_dummy_transmission(bcm);
608 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
609 bcm43xx_ilt_write(bcm, 0x3001, tval);
611 bcm43xx_radio_set_txpower_a(bcm, 0x0018);
613 bcm43xx_radio_clear_tssi(bcm);
616 static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
618 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
621 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
622 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
623 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
624 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
625 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
627 for (offset = 0x0089; offset < 0x00A7; offset++) {
628 bcm43xx_phy_write(bcm, offset, val);
631 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
632 if (radio->channel == 0xFF)
633 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
635 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
636 if (radio->version != 0x2050) {
637 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
638 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
640 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
641 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
642 if (radio->version == 0x2050) {
643 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
644 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
645 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
646 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
647 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
648 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
649 bcm43xx_radio_init2050(bcm);
651 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
652 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
653 bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
654 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
655 bcm43xx_phy_lo_b_measure(bcm);
656 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
657 if (radio->version != 0x2050)
658 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
659 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
660 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
661 if (radio->version != 0x2050)
662 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
663 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
664 bcm43xx_phy_init_pctl(bcm);
667 static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
669 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
672 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
673 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
674 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
675 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
676 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
678 for (offset = 0x0089; offset < 0x00A7; offset++) {
679 bcm43xx_phy_write(bcm, offset, val);
682 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
683 if (radio->channel == 0xFF)
684 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
686 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
687 if (radio->version != 0x2050) {
688 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
689 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
691 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
692 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
693 if (radio->version == 0x2050) {
694 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
695 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
696 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
697 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
698 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
699 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
700 bcm43xx_radio_init2050(bcm);
702 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
703 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
704 if (radio->version == 0x2050)
705 bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
706 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
708 bcm43xx_phy_lo_b_measure(bcm);
710 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
711 if (radio->version == 0x2050)
712 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
713 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
714 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
715 if (radio->version == 0x2050)
716 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
717 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
718 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
719 bcm43xx_calc_nrssi_slope(bcm);
720 bcm43xx_calc_nrssi_threshold(bcm);
722 bcm43xx_phy_init_pctl(bcm);
725 static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
727 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
728 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
731 if (phy->version == 1 &&
732 radio->version == 0x2050) {
733 bcm43xx_radio_write16(bcm, 0x007A,
734 bcm43xx_radio_read16(bcm, 0x007A)
737 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
738 (bcm->board_type != 0x0416)) {
739 for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
740 bcm43xx_phy_write(bcm, offset,
741 (bcm43xx_phy_read(bcm, offset) + 0x2020)
745 bcm43xx_phy_write(bcm, 0x0035,
746 (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
748 if (radio->version == 0x2050)
749 bcm43xx_phy_write(bcm, 0x0038, 0x0667);
751 if (phy->connected) {
752 if (radio->version == 0x2050) {
753 bcm43xx_radio_write16(bcm, 0x007A,
754 bcm43xx_radio_read16(bcm, 0x007A)
756 bcm43xx_radio_write16(bcm, 0x0051,
757 bcm43xx_radio_read16(bcm, 0x0051)
760 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
762 bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
763 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
765 bcm43xx_phy_write(bcm, 0x001C, 0x186A);
767 bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
768 bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
769 bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
772 if (bcm->bad_frames_preempt) {
773 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
774 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
777 if (phy->version == 1 && radio->version == 0x2050) {
778 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
779 bcm43xx_phy_write(bcm, 0x0021, 0x3763);
780 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
781 bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
782 bcm43xx_phy_write(bcm, 0x0024, 0x037E);
784 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
785 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
786 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
788 if (phy->version == 1 && radio->version == 0x2050)
789 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
791 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
793 if (phy->version == 0)
794 bcm43xx_write16(bcm, 0x03E4, 0x3000);
796 /* Force to channel 7, even if not supported. */
797 bcm43xx_radio_selectchannel(bcm, 7, 0);
799 if (radio->version != 0x2050) {
800 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
801 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
804 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
805 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
807 if (radio->version == 0x2050) {
808 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
809 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
812 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
813 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
815 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
817 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
819 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
820 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
821 bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
823 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
825 if (radio->version == 0x2050)
826 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
828 bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
831 static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
833 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
834 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
837 bcm43xx_phy_write(bcm, 0x003E, 0x817A);
838 bcm43xx_radio_write16(bcm, 0x007A,
839 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
840 if ((radio->manufact == 0x17F) &&
841 (radio->version == 0x2050) &&
842 (radio->revision == 3 ||
843 radio->revision == 4 ||
844 radio->revision == 5)) {
845 bcm43xx_radio_write16(bcm, 0x0051, 0x001F);
846 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
847 bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
848 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
849 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
850 bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
851 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
852 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
853 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
855 if ((radio->manufact == 0x17F) &&
856 (radio->version == 0x2050) &&
857 (radio->revision == 6)) {
858 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
859 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
860 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
861 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
862 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
863 bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
864 bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
865 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
866 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
867 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
868 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
869 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
871 if ((radio->manufact == 0x17F) &&
872 (radio->version == 0x2050) &&
873 (radio->revision == 7)) {
874 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
875 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
876 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
877 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
878 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
879 bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
880 bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
881 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
882 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
883 bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
884 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
885 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
886 bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
888 if ((radio->manufact == 0x17F) &&
889 (radio->version == 0x2050) &&
890 (radio->revision == 8)) {
891 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
892 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
893 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
894 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
895 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
896 bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
897 bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
898 if (bcm->sprom.boardflags & 0x8000) {
899 bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
900 bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
902 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
903 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
905 bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
906 bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
907 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
908 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
911 for (offset = 0x0088; offset < 0x0098; offset++) {
912 bcm43xx_phy_write(bcm, offset, val);
916 for (offset = 0x0098; offset < 0x00A8; offset++) {
917 bcm43xx_phy_write(bcm, offset, val);
921 for (offset = 0x00A8; offset < 0x00C8; offset++) {
922 bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
925 if (phy->type == BCM43xx_PHYTYPE_G) {
926 bcm43xx_radio_write16(bcm, 0x007A,
927 bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
928 bcm43xx_radio_write16(bcm, 0x0051,
929 bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
930 bcm43xx_phy_write(bcm, 0x0802,
931 bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
932 bcm43xx_phy_write(bcm, 0x042B,
933 bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
936 /* Force to channel 7, even if not supported. */
937 bcm43xx_radio_selectchannel(bcm, 7, 0);
939 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
940 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
942 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002));
943 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
944 if (radio->manufact == 0x17F &&
945 radio->version == 0x2050 &&
946 radio->revision <= 2) {
947 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
948 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
949 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
950 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
952 bcm43xx_radio_write16(bcm, 0x007A,
953 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
955 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
957 bcm43xx_phy_write(bcm, 0x0014, 0x0200);
958 if (radio->version == 0x2050){
959 if (radio->revision == 3 ||
960 radio->revision == 4 ||
961 radio->revision == 5)
962 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
964 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
966 bcm43xx_phy_write(bcm, 0x0038, 0x0668);
967 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
968 if (radio->version == 0x2050) {
969 if (radio->revision == 3 ||
970 radio->revision == 4 ||
971 radio->revision == 5)
972 bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
973 else if (radio->revision <= 2)
974 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
978 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
980 bcm43xx_write16(bcm, 0x03E4, 0x0009);
981 if (phy->type == BCM43xx_PHYTYPE_B) {
982 bcm43xx_write16(bcm, 0x03E6, 0x8140);
983 bcm43xx_phy_write(bcm, 0x0016, 0x0410);
984 bcm43xx_phy_write(bcm, 0x0017, 0x0820);
985 bcm43xx_phy_write(bcm, 0x0062, 0x0007);
986 (void) bcm43xx_radio_calibrationvalue(bcm);
987 bcm43xx_phy_lo_b_measure(bcm);
988 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
989 bcm43xx_calc_nrssi_slope(bcm);
990 bcm43xx_calc_nrssi_threshold(bcm);
992 bcm43xx_phy_init_pctl(bcm);
994 bcm43xx_write16(bcm, 0x03E6, 0x0);
997 static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
999 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1000 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1002 u16 backup_radio[3];
1005 u16 loop1_cnt, loop1_done, loop1_omitted;
1008 backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
1009 backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
1010 backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
1011 backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
1012 backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
1013 backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
1014 backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
1015 backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
1016 backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
1017 backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
1018 backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
1019 backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
1020 backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
1021 backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
1022 backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
1023 bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
1024 backup_bband = radio->baseband_atten;
1025 backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
1026 backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
1027 backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
1029 bcm43xx_phy_write(bcm, 0x0429,
1030 bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
1031 bcm43xx_phy_write(bcm, 0x0001,
1032 bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
1033 bcm43xx_phy_write(bcm, 0x0811,
1034 bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
1035 bcm43xx_phy_write(bcm, 0x0812,
1036 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
1037 bcm43xx_phy_write(bcm, 0x0811,
1038 bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
1039 bcm43xx_phy_write(bcm, 0x0812,
1040 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
1041 bcm43xx_phy_write(bcm, 0x0814,
1042 bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
1043 bcm43xx_phy_write(bcm, 0x0815,
1044 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
1045 bcm43xx_phy_write(bcm, 0x0814,
1046 bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
1047 bcm43xx_phy_write(bcm, 0x0815,
1048 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
1049 bcm43xx_phy_write(bcm, 0x0811,
1050 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
1051 bcm43xx_phy_write(bcm, 0x0812,
1052 bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
1054 bcm43xx_phy_write(bcm, 0x0811,
1055 (bcm43xx_phy_read(bcm, 0x0811)
1056 & 0xFFCF) | 0x0030);
1057 bcm43xx_phy_write(bcm, 0x0812,
1058 (bcm43xx_phy_read(bcm, 0x0812)
1059 & 0xFFCF) | 0x0010);
1061 bcm43xx_phy_write(bcm, 0x005A, 0x0780);
1062 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1063 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1064 if (phy->version == 0) {
1065 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
1067 bcm43xx_phy_write(bcm, 0x000A,
1068 bcm43xx_phy_read(bcm, 0x000A)
1071 bcm43xx_phy_write(bcm, 0x0814,
1072 bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
1073 bcm43xx_phy_write(bcm, 0x0815,
1074 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
1075 bcm43xx_phy_write(bcm, 0x0003,
1076 (bcm43xx_phy_read(bcm, 0x0003)
1077 & 0xFF9F) | 0x0040);
1078 if (radio->version == 0x2050 && radio->revision == 2) {
1079 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1080 bcm43xx_radio_write16(bcm, 0x0043,
1081 (bcm43xx_radio_read16(bcm, 0x0043)
1082 & 0xFFF0) | 0x0009);
1084 } else if (radio->revision == 8) {
1085 bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
1090 bcm43xx_phy_set_baseband_attenuation(bcm, 11);
1093 bcm43xx_phy_write(bcm, 0x080F, 0xC020);
1095 bcm43xx_phy_write(bcm, 0x080F, 0x8020);
1096 bcm43xx_phy_write(bcm, 0x0810, 0x0000);
1098 bcm43xx_phy_write(bcm, 0x002B,
1099 (bcm43xx_phy_read(bcm, 0x002B)
1100 & 0xFFC0) | 0x0001);
1101 bcm43xx_phy_write(bcm, 0x002B,
1102 (bcm43xx_phy_read(bcm, 0x002B)
1103 & 0xC0FF) | 0x0800);
1104 bcm43xx_phy_write(bcm, 0x0811,
1105 bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
1106 bcm43xx_phy_write(bcm, 0x0812,
1107 bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
1108 if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
1109 if (phy->rev >= 7) {
1110 bcm43xx_phy_write(bcm, 0x0811,
1111 bcm43xx_phy_read(bcm, 0x0811)
1113 bcm43xx_phy_write(bcm, 0x0812,
1114 bcm43xx_phy_read(bcm, 0x0812)
1118 bcm43xx_radio_write16(bcm, 0x007A,
1119 bcm43xx_radio_read16(bcm, 0x007A)
1122 for (i = 0; i < loop1_cnt; i++) {
1123 bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
1124 bcm43xx_phy_write(bcm, 0x0812,
1125 (bcm43xx_phy_read(bcm, 0x0812)
1126 & 0xF0FF) | (i << 8));
1127 bcm43xx_phy_write(bcm, 0x0015,
1128 (bcm43xx_phy_read(bcm, 0x0015)
1129 & 0x0FFF) | 0xA000);
1130 bcm43xx_phy_write(bcm, 0x0015,
1131 (bcm43xx_phy_read(bcm, 0x0015)
1132 & 0x0FFF) | 0xF000);
1134 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1138 loop1_omitted = loop1_cnt - loop1_done;
1141 if (loop1_done >= 8) {
1142 bcm43xx_phy_write(bcm, 0x0812,
1143 bcm43xx_phy_read(bcm, 0x0812)
1145 for (i = loop1_done - 8; i < 16; i++) {
1146 bcm43xx_phy_write(bcm, 0x0812,
1147 (bcm43xx_phy_read(bcm, 0x0812)
1148 & 0xF0FF) | (i << 8));
1149 bcm43xx_phy_write(bcm, 0x0015,
1150 (bcm43xx_phy_read(bcm, 0x0015)
1151 & 0x0FFF) | 0xA000);
1152 bcm43xx_phy_write(bcm, 0x0015,
1153 (bcm43xx_phy_read(bcm, 0x0015)
1154 & 0x0FFF) | 0xF000);
1156 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1161 bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
1162 bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
1163 bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
1164 bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
1165 bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
1166 bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
1167 bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
1168 bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
1169 bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
1170 bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
1171 bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
1173 bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
1175 bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
1176 bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
1177 bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
1179 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
1181 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
1182 bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
1183 bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
1184 bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
1186 phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
1187 phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
1190 static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1192 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1193 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1197 bcm43xx_phy_initb5(bcm);
1198 else if (phy->rev >= 2 && phy->rev <= 7)
1199 bcm43xx_phy_initb6(bcm);
1200 if (phy->rev >= 2 || phy->connected)
1201 bcm43xx_phy_inita(bcm);
1203 if (phy->rev >= 2) {
1204 bcm43xx_phy_write(bcm, 0x0814, 0x0000);
1205 bcm43xx_phy_write(bcm, 0x0815, 0x0000);
1207 bcm43xx_phy_write(bcm, 0x0811, 0x0000);
1208 else if (phy->rev >= 3)
1209 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1210 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1211 if (phy->connected) {
1212 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
1214 bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
1215 bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
1217 bcm43xx_phy_write(bcm, 0x04CC,
1218 (bcm43xx_phy_read(bcm, 0x04CC)
1219 & 0x00FF) | 0x1F00);
1224 if (phy->rev < 3 && phy->connected)
1225 bcm43xx_phy_write(bcm, 0x047E, 0x0078);
1226 if (phy->rev >= 6 && phy->rev <= 8) {
1227 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
1228 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
1230 if (phy->rev >= 2 && phy->connected)
1231 bcm43xx_calc_loopback_gain(bcm);
1232 if (radio->revision != 8) {
1233 if (radio->initval == 0xFFFF)
1234 radio->initval = bcm43xx_radio_init2050(bcm);
1236 bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
1238 if (radio->txctl2 == 0xFFFF) {
1239 bcm43xx_phy_lo_g_measure(bcm);
1241 if (radio->version == 0x2050 && radio->revision == 8) {
1244 bcm43xx_radio_write16(bcm, 0x0052,
1245 (bcm43xx_radio_read16(bcm, 0x0052)
1246 & 0xFFF0) | radio->txctl1);
1248 if (phy->rev >= 6) {
1250 bcm43xx_phy_write(bcm, 0x0036,
1251 (bcm43xx_phy_read(bcm, 0x0036)
1252 & 0xF000) | (FIXME << 12));
1255 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
1256 bcm43xx_phy_write(bcm, 0x002E, 0x8075);
1258 bcm43xx_phy_write(bcm, 0x003E, 0x807F);
1260 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1262 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1264 if (phy->connected) {
1265 bcm43xx_phy_lo_adjust(bcm, 0);
1266 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1269 if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
1270 /* The specs state to update the NRSSI LT with
1271 * the value 0x7FFFFFFF here. I think that is some weird
1272 * compiler optimization in the original driver.
1273 * Essentially, what we do here is resetting all NRSSI LT
1274 * entries to -32 (see the limit_value() in nrssi_hw_update())
1276 bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
1277 bcm43xx_calc_nrssi_threshold(bcm);
1278 } else if (phy->connected) {
1279 if (radio->nrssi[0] == -1000) {
1280 assert(radio->nrssi[1] == -1000);
1281 bcm43xx_calc_nrssi_slope(bcm);
1283 assert(radio->nrssi[1] != -1000);
1284 bcm43xx_calc_nrssi_threshold(bcm);
1287 if (radio->revision == 8)
1288 bcm43xx_phy_write(bcm, 0x0805, 0x3230);
1289 bcm43xx_phy_init_pctl(bcm);
1290 if (bcm->chip_id == 0x4306 && bcm->chip_package == 2) {
1291 bcm43xx_phy_write(bcm, 0x0429,
1292 bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
1293 bcm43xx_phy_write(bcm, 0x04C3,
1294 bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
1298 static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
1303 for (i = 0; i < 10; i++){
1304 bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
1306 bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
1308 bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
1310 ret += bcm43xx_phy_read(bcm, 0x002C);
1316 void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
1318 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1319 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1320 u16 regstack[12] = { 0 };
1325 regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
1326 regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
1328 if (radio->version == 0x2053) {
1329 regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
1330 regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
1331 regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
1332 regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
1333 regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
1334 regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
1336 regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
1337 regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
1338 regstack[10] = bcm43xx_read16(bcm, 0x03EC);
1339 regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
1341 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
1342 bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
1343 bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
1344 bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
1346 bcm43xx_phy_write(bcm, 0x0015, 0xB000);
1347 bcm43xx_phy_write(bcm, 0x002B, 0x0004);
1349 if (radio->version == 0x2053) {
1350 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1351 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1354 phy->minlowsig[0] = 0xFFFF;
1356 for (i = 0; i < 4; i++) {
1357 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1358 bcm43xx_phy_lo_b_r15_loop(bcm);
1360 for (i = 0; i < 10; i++) {
1361 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1362 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1363 if (mls < phy->minlowsig[0]) {
1364 phy->minlowsig[0] = mls;
1365 phy->minlowsigpos[0] = i;
1368 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
1370 phy->minlowsig[1] = 0xFFFF;
1372 for (i = -4; i < 5; i += 2) {
1373 for (j = -4; j < 5; j += 2) {
1375 fval = (0x0100 * i) + j + 0x0100;
1377 fval = (0x0100 * i) + j;
1378 bcm43xx_phy_write(bcm, 0x002F, fval);
1379 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1380 if (mls < phy->minlowsig[1]) {
1381 phy->minlowsig[1] = mls;
1382 phy->minlowsigpos[1] = fval;
1386 phy->minlowsigpos[1] += 0x0101;
1388 bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
1389 if (radio->version == 0x2053) {
1390 bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
1391 bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
1392 bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
1393 bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
1394 bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
1395 bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
1397 bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
1398 bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
1400 bcm43xx_radio_write16(bcm, 0x0052,
1401 (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
1404 bcm43xx_write16(bcm, 0x03EC, regstack[10]);
1406 bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
1410 u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
1412 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1414 unsigned long flags;
1416 local_irq_save(flags);
1417 if (phy->connected) {
1418 bcm43xx_phy_write(bcm, 0x15, 0xE300);
1420 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
1422 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
1424 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
1426 bcm43xx_phy_write(bcm, 0x0015, 0xF300);
1429 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
1431 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
1433 bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
1436 ret = bcm43xx_phy_read(bcm, 0x002D);
1437 local_irq_restore(flags);
1442 static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
1447 for (i = 0; i < 8; i++)
1448 ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
1453 /* Write the LocalOscillator CONTROL */
1455 void bcm43xx_lo_write(struct bcm43xx_private *bcm,
1456 struct bcm43xx_lopair *pair)
1460 value = (u8)(pair->low);
1461 value |= ((u8)(pair->high)) << 8;
1463 #ifdef CONFIG_BCM43XX_DEBUG
1465 if (pair->low < -8 || pair->low > 8 ||
1466 pair->high < -8 || pair->high > 8) {
1467 printk(KERN_WARNING PFX
1468 "WARNING: Writing invalid LOpair "
1469 "(low: %d, high: %d, index: %lu)\n",
1470 pair->low, pair->high,
1471 (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
1476 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
1480 struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
1481 u16 baseband_attenuation,
1482 u16 radio_attenuation,
1485 static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
1486 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1488 if (baseband_attenuation > 6)
1489 baseband_attenuation = 6;
1490 assert(radio_attenuation < 10);
1493 return bcm43xx_get_lopair(phy,
1495 baseband_attenuation);
1497 return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
1501 struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
1503 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1505 return bcm43xx_find_lopair(bcm,
1506 radio->baseband_atten,
1512 void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
1514 struct bcm43xx_lopair *pair;
1517 /* Use fixed values. Only for initialization. */
1518 pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
1520 pair = bcm43xx_current_lopair(bcm);
1521 bcm43xx_lo_write(bcm, pair);
1524 static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
1526 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1530 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1532 smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1533 for (i = 0; i < 16; i++) {
1534 bcm43xx_radio_write16(bcm, 0x0052, i);
1536 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1537 if (tmp < smallest) {
1542 radio->txctl2 = txctl2;
1546 void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
1547 const struct bcm43xx_lopair *in_pair,
1548 struct bcm43xx_lopair *out_pair,
1551 static const struct bcm43xx_lopair transitions[8] = {
1552 { .high = 1, .low = 1, },
1553 { .high = 1, .low = 0, },
1554 { .high = 1, .low = -1, },
1555 { .high = 0, .low = -1, },
1556 { .high = -1, .low = -1, },
1557 { .high = -1, .low = 0, },
1558 { .high = -1, .low = 1, },
1559 { .high = 0, .low = 1, },
1561 struct bcm43xx_lopair lowest_transition = {
1562 .high = in_pair->high,
1563 .low = in_pair->low,
1565 struct bcm43xx_lopair tmp_pair;
1566 struct bcm43xx_lopair transition;
1571 u32 lowest_deviation;
1574 /* Note that in_pair and out_pair can point to the same pair. Be careful. */
1576 bcm43xx_lo_write(bcm, &lowest_transition);
1577 lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1580 assert(state >= 0 && state <= 8);
1584 } else if (state % 2 == 0) {
1597 tmp_pair.high = lowest_transition.high;
1598 tmp_pair.low = lowest_transition.low;
1600 assert(j >= 1 && j <= 8);
1601 transition.high = tmp_pair.high + transitions[j - 1].high;
1602 transition.low = tmp_pair.low + transitions[j - 1].low;
1603 if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
1604 bcm43xx_lo_write(bcm, &transition);
1605 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1606 if (tmp < lowest_deviation) {
1607 lowest_deviation = tmp;
1611 lowest_transition.high = transition.high;
1612 lowest_transition.low = transition.low;
1622 } while (i-- && found_lower);
1624 out_pair->high = lowest_transition.high;
1625 out_pair->low = lowest_transition.low;
1628 /* Set the baseband attenuation value on chip. */
1629 void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
1630 u16 baseband_attenuation)
1632 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1635 if (phy->version == 0) {
1636 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
1637 value |= (baseband_attenuation & 0x000F);
1638 bcm43xx_write16(bcm, 0x03E6, value);
1642 if (phy->version > 1) {
1643 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
1644 value |= (baseband_attenuation << 2) & 0x003C;
1646 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
1647 value |= (baseband_attenuation << 3) & 0x0078;
1649 bcm43xx_phy_write(bcm, 0x0060, value);
1652 /* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
1653 void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
1655 static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
1656 const int is_initializing = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZING);
1657 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1658 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1659 u16 h, i, oldi = 0, j;
1660 struct bcm43xx_lopair control;
1661 struct bcm43xx_lopair *tmp_control;
1663 u16 regstack[16] = { 0 };
1666 //XXX: What are these?
1669 oldchannel = radio->channel;
1671 if (phy->connected) {
1672 regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
1673 regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
1674 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1675 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1677 regstack[3] = bcm43xx_read16(bcm, 0x03E2);
1678 bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
1679 regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1680 regstack[5] = bcm43xx_phy_read(bcm, 0x15);
1681 regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
1682 regstack[7] = bcm43xx_phy_read(bcm, 0x35);
1683 regstack[8] = bcm43xx_phy_read(bcm, 0x60);
1684 regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
1685 regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
1686 regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
1687 if (phy->connected) {
1688 regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
1689 regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
1690 regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
1691 regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
1693 bcm43xx_radio_selectchannel(bcm, 6, 0);
1694 if (phy->connected) {
1695 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1696 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1697 bcm43xx_dummy_transmission(bcm);
1699 bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
1701 bcm43xx_phy_set_baseband_attenuation(bcm, 2);
1703 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
1704 bcm43xx_phy_write(bcm, 0x002E, 0x007F);
1705 bcm43xx_phy_write(bcm, 0x080F, 0x0078);
1706 bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
1707 bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
1708 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1709 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1710 if (phy->connected) {
1711 bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
1712 bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
1713 bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
1714 bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
1716 if (is_initializing)
1717 bcm43xx_phy_lo_g_measure_txctl2(bcm);
1718 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1723 for (h = 0; h < 10; h++) {
1724 /* Loop over each possible RadioAttenuation (0-9) */
1726 if (is_initializing) {
1730 } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
1731 ((i % 2 == 0) && (oldi % 2 == 0))) {
1732 tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
1733 memcpy(&control, tmp_control, sizeof(control));
1735 tmp_control = bcm43xx_get_lopair(phy, 3, 0);
1736 memcpy(&control, tmp_control, sizeof(control));
1739 /* Loop over each possible BasebandAttenuation/2 */
1740 for (j = 0; j < 4; j++) {
1741 if (is_initializing) {
1753 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1754 if (!tmp_control->used)
1756 memcpy(&control, tmp_control, sizeof(control));
1760 bcm43xx_radio_write16(bcm, 0x43, i);
1761 bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
1764 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1766 tmp = (regstack[10] & 0xFFF0);
1769 bcm43xx_radio_write16(bcm, 0x007A, tmp);
1771 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1772 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1776 /* Loop over each possible RadioAttenuation (10-13) */
1777 for (i = 10; i < 14; i++) {
1778 /* Loop over each possible BasebandAttenuation/2 */
1779 for (j = 0; j < 4; j++) {
1780 if (is_initializing) {
1781 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1782 memcpy(&control, tmp_control, sizeof(control));
1783 tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
1794 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1795 if (!tmp_control->used)
1797 memcpy(&control, tmp_control, sizeof(control));
1801 bcm43xx_radio_write16(bcm, 0x43, i - 9);
1802 bcm43xx_radio_write16(bcm, 0x52,
1804 | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
1807 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1809 tmp = (regstack[10] & 0xFFF0);
1812 bcm43xx_radio_write16(bcm, 0x7A, tmp);
1814 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1815 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1820 if (phy->connected) {
1821 bcm43xx_phy_write(bcm, 0x0015, 0xE300);
1822 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
1824 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
1826 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
1828 bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
1829 bcm43xx_phy_lo_adjust(bcm, is_initializing);
1830 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1832 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1834 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1835 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
1836 bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
1837 bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
1838 bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
1839 bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
1840 bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
1841 bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
1842 regstack[11] &= 0x00F0;
1843 regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
1844 bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
1845 bcm43xx_write16(bcm, 0x03E2, regstack[3]);
1846 if (phy->connected) {
1847 bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
1848 bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
1849 bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
1850 bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
1851 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
1852 bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
1854 bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
1856 #ifdef CONFIG_BCM43XX_DEBUG
1858 /* Sanity check for all lopairs. */
1859 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1860 tmp_control = phy->_lo_pairs + i;
1861 if (tmp_control->low < -8 || tmp_control->low > 8 ||
1862 tmp_control->high < -8 || tmp_control->high > 8) {
1863 printk(KERN_WARNING PFX
1864 "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
1865 tmp_control->low, tmp_control->high, i);
1869 #endif /* CONFIG_BCM43XX_DEBUG */
1873 void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
1875 struct bcm43xx_lopair *pair;
1877 pair = bcm43xx_current_lopair(bcm);
1881 void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
1883 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1884 struct bcm43xx_lopair *pair;
1887 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1888 pair = phy->_lo_pairs + i;
1893 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1894 * This function converts a TSSI value to dBm in Q5.2
1896 static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
1898 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1902 tmp = phy->idle_tssi;
1904 tmp -= phy->savedpctlreg;
1906 switch (phy->type) {
1907 case BCM43xx_PHYTYPE_A:
1909 tmp = limit_value(tmp, 0x00, 0xFF);
1910 dbm = phy->tssi2dbm[tmp];
1911 TODO(); //TODO: There's a FIXME on the specs
1913 case BCM43xx_PHYTYPE_B:
1914 case BCM43xx_PHYTYPE_G:
1915 tmp = limit_value(tmp, 0x00, 0x3F);
1916 dbm = phy->tssi2dbm[tmp];
1925 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1926 void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
1928 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1929 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1931 if (phy->savedpctlreg == 0xFFFF)
1933 if ((bcm->board_type == 0x0416) &&
1934 (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
1937 switch (phy->type) {
1938 case BCM43xx_PHYTYPE_A: {
1940 TODO(); //TODO: Nothing for A PHYs yet :-/
1944 case BCM43xx_PHYTYPE_B:
1945 case BCM43xx_PHYTYPE_G: {
1951 s16 desired_pwr, estimated_pwr, pwr_adjust;
1952 s16 radio_att_delta, baseband_att_delta;
1953 s16 radio_attenuation, baseband_attenuation;
1954 unsigned long phylock_flags;
1956 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
1957 v0 = (s8)(tmp & 0x00FF);
1958 v1 = (s8)((tmp & 0xFF00) >> 8);
1959 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
1960 v2 = (s8)(tmp & 0x00FF);
1961 v3 = (s8)((tmp & 0xFF00) >> 8);
1964 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
1965 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
1966 v0 = (s8)(tmp & 0x00FF);
1967 v1 = (s8)((tmp & 0xFF00) >> 8);
1968 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
1969 v2 = (s8)(tmp & 0x00FF);
1970 v3 = (s8)((tmp & 0xFF00) >> 8);
1971 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
1973 v0 = (v0 + 0x20) & 0x3F;
1974 v1 = (v1 + 0x20) & 0x3F;
1975 v2 = (v2 + 0x20) & 0x3F;
1976 v3 = (v3 + 0x20) & 0x3F;
1979 bcm43xx_radio_clear_tssi(bcm);
1981 average = (v0 + v1 + v2 + v3 + 2) / 4;
1983 if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
1986 estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
1988 max_pwr = bcm->sprom.maxpower_bgphy;
1990 if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
1991 (phy->type == BCM43xx_PHYTYPE_G))
1995 max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
1996 where REG is the max power as per the regulatory domain
1999 desired_pwr = limit_value(radio->txpower_desired, 0, max_pwr);
2000 /* Check if we need to adjust the current power. */
2001 pwr_adjust = desired_pwr - estimated_pwr;
2002 radio_att_delta = -(pwr_adjust + 7) >> 3;
2003 baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
2004 if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
2005 bcm43xx_phy_lo_mark_current_used(bcm);
2009 /* Calculate the new attenuation values. */
2010 baseband_attenuation = radio->baseband_atten;
2011 baseband_attenuation += baseband_att_delta;
2012 radio_attenuation = radio->radio_atten;
2013 radio_attenuation += radio_att_delta;
2015 /* Get baseband and radio attenuation values into their permitted ranges.
2016 * baseband 0-11, radio 0-9.
2017 * Radio attenuation affects power level 4 times as much as baseband.
2019 if (radio_attenuation < 0) {
2020 baseband_attenuation -= (4 * -radio_attenuation);
2021 radio_attenuation = 0;
2022 } else if (radio_attenuation > 9) {
2023 baseband_attenuation += (4 * (radio_attenuation - 9));
2024 radio_attenuation = 9;
2026 while (baseband_attenuation < 0 && radio_attenuation > 0) {
2027 baseband_attenuation += 4;
2028 radio_attenuation--;
2030 while (baseband_attenuation > 11 && radio_attenuation < 9) {
2031 baseband_attenuation -= 4;
2032 radio_attenuation++;
2035 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2037 txpower = radio->txctl1;
2038 if ((radio->version == 0x2050) && (radio->revision == 2)) {
2039 if (radio_attenuation <= 1) {
2042 radio_attenuation += 2;
2043 baseband_attenuation += 2;
2044 } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2045 baseband_attenuation += 4 * (radio_attenuation - 2);
2046 radio_attenuation = 2;
2048 } else if (radio_attenuation > 4 && txpower != 0) {
2050 if (baseband_attenuation < 3) {
2051 radio_attenuation -= 3;
2052 baseband_attenuation += 2;
2054 radio_attenuation -= 2;
2055 baseband_attenuation -= 2;
2059 radio->txctl1 = txpower;
2060 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2061 radio_attenuation = limit_value(radio_attenuation, 0, 9);
2063 bcm43xx_phy_lock(bcm, phylock_flags);
2064 bcm43xx_radio_lock(bcm);
2065 bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
2066 radio_attenuation, txpower);
2067 bcm43xx_phy_lo_mark_current_used(bcm);
2068 bcm43xx_radio_unlock(bcm);
2069 bcm43xx_phy_unlock(bcm, phylock_flags);
2078 s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
2083 return (num+den/2)/den;
2087 s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
2089 s32 m1, m2, f = 256, q, delta;
2092 m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2093 m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2097 q = bcm43xx_tssi2dbm_ad(f * 4096 -
2098 bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2102 } while (delta >= 2);
2103 entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2107 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2108 int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
2110 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2111 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2112 s16 pab0, pab1, pab2;
2116 if (phy->type == BCM43xx_PHYTYPE_A) {
2117 pab0 = (s16)(bcm->sprom.pa1b0);
2118 pab1 = (s16)(bcm->sprom.pa1b1);
2119 pab2 = (s16)(bcm->sprom.pa1b2);
2121 pab0 = (s16)(bcm->sprom.pa0b0);
2122 pab1 = (s16)(bcm->sprom.pa0b1);
2123 pab2 = (s16)(bcm->sprom.pa0b2);
2126 if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
2127 phy->idle_tssi = 0x34;
2128 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2132 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2133 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2134 /* The pabX values are set in SPROM. Use them. */
2135 if (phy->type == BCM43xx_PHYTYPE_A) {
2136 if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
2137 (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
2138 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
2140 phy->idle_tssi = 62;
2142 if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
2143 (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
2144 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
2146 phy->idle_tssi = 62;
2148 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2149 if (dyn_tssi2dbm == NULL) {
2150 printk(KERN_ERR PFX "Could not allocate memory"
2151 "for tssi2dbm table\n");
2154 for (idx = 0; idx < 64; idx++)
2155 if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2156 phy->tssi2dbm = NULL;
2157 printk(KERN_ERR PFX "Could not generate "
2158 "tssi2dBm table\n");
2159 kfree(dyn_tssi2dbm);
2162 phy->tssi2dbm = dyn_tssi2dbm;
2163 phy->dyn_tssi_tbl = 1;
2165 /* pabX values not set in SPROM. */
2166 switch (phy->type) {
2167 case BCM43xx_PHYTYPE_A:
2168 /* APHY needs a generated table. */
2169 phy->tssi2dbm = NULL;
2170 printk(KERN_ERR PFX "Could not generate tssi2dBm "
2171 "table (wrong SPROM info)!\n");
2173 case BCM43xx_PHYTYPE_B:
2174 phy->idle_tssi = 0x34;
2175 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2177 case BCM43xx_PHYTYPE_G:
2178 phy->idle_tssi = 0x34;
2179 phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
2187 int bcm43xx_phy_init(struct bcm43xx_private *bcm)
2189 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2191 unsigned long flags;
2193 /* We do not want to be preempted while calibrating
2196 local_irq_save(flags);
2198 switch (phy->type) {
2199 case BCM43xx_PHYTYPE_A:
2200 if (phy->rev == 2 || phy->rev == 3) {
2201 bcm43xx_phy_inita(bcm);
2205 case BCM43xx_PHYTYPE_B:
2208 bcm43xx_phy_initb2(bcm);
2212 bcm43xx_phy_initb4(bcm);
2216 bcm43xx_phy_initb5(bcm);
2220 bcm43xx_phy_initb6(bcm);
2225 case BCM43xx_PHYTYPE_G:
2226 bcm43xx_phy_initg(bcm);
2230 local_irq_restore(flags);
2232 printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
2237 void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
2239 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2245 antennadiv = phy->antenna_diversity;
2247 if (antennadiv == 0xFFFF)
2249 assert(antennadiv <= 3);
2251 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2252 BCM43xx_UCODEFLAGS_OFFSET);
2253 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2254 BCM43xx_UCODEFLAGS_OFFSET,
2255 ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
2257 switch (phy->type) {
2258 case BCM43xx_PHYTYPE_A:
2259 case BCM43xx_PHYTYPE_G:
2260 if (phy->type == BCM43xx_PHYTYPE_A)
2265 if (antennadiv == 2)
2266 value = (3/*automatic*/ << 7);
2268 value = (antennadiv << 7);
2269 bcm43xx_phy_write(bcm, offset + 1,
2270 (bcm43xx_phy_read(bcm, offset + 1)
2273 if (antennadiv >= 2) {
2274 if (antennadiv == 2)
2275 value = (antennadiv << 7);
2277 value = (0/*force0*/ << 7);
2278 bcm43xx_phy_write(bcm, offset + 0x2B,
2279 (bcm43xx_phy_read(bcm, offset + 0x2B)
2283 if (phy->type == BCM43xx_PHYTYPE_G) {
2284 if (antennadiv >= 2)
2285 bcm43xx_phy_write(bcm, 0x048C,
2286 bcm43xx_phy_read(bcm, 0x048C)
2289 bcm43xx_phy_write(bcm, 0x048C,
2290 bcm43xx_phy_read(bcm, 0x048C)
2292 if (phy->rev >= 2) {
2293 bcm43xx_phy_write(bcm, 0x0461,
2294 bcm43xx_phy_read(bcm, 0x0461)
2296 bcm43xx_phy_write(bcm, 0x04AD,
2297 (bcm43xx_phy_read(bcm, 0x04AD)
2298 & 0x00FF) | 0x0015);
2300 bcm43xx_phy_write(bcm, 0x0427, 0x0008);
2302 bcm43xx_phy_write(bcm, 0x0427,
2303 (bcm43xx_phy_read(bcm, 0x0427)
2304 & 0x00FF) | 0x0008);
2306 else if (phy->rev >= 6)
2307 bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
2310 bcm43xx_phy_write(bcm, 0x002B,
2311 (bcm43xx_phy_read(bcm, 0x002B)
2312 & 0x00FF) | 0x0024);
2314 bcm43xx_phy_write(bcm, 0x0061,
2315 bcm43xx_phy_read(bcm, 0x0061)
2317 if (phy->rev == 3) {
2318 bcm43xx_phy_write(bcm, 0x0093, 0x001D);
2319 bcm43xx_phy_write(bcm, 0x0027, 0x0008);
2321 bcm43xx_phy_write(bcm, 0x0093, 0x003A);
2322 bcm43xx_phy_write(bcm, 0x0027,
2323 (bcm43xx_phy_read(bcm, 0x0027)
2324 & 0x00FF) | 0x0008);
2329 case BCM43xx_PHYTYPE_B:
2330 if (bcm->current_core->rev == 2)
2331 value = (3/*automatic*/ << 7);
2333 value = (antennadiv << 7);
2334 bcm43xx_phy_write(bcm, 0x03E2,
2335 (bcm43xx_phy_read(bcm, 0x03E2)
2342 if (antennadiv >= 2) {
2343 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2344 BCM43xx_UCODEFLAGS_OFFSET);
2345 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2346 BCM43xx_UCODEFLAGS_OFFSET,
2347 ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
2350 phy->antenna_diversity = antennadiv;