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
<= 8))
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
);
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) {
1244 bcm43xx_radio_write16(bcm
, 0x0052,
1245 (radio
->txctl1
<< 4) | radio
->txctl2
);
1247 bcm43xx_radio_write16(bcm
, 0x0052,
1248 (bcm43xx_radio_read16(bcm
, 0x0052)
1249 & 0xFFF0) | radio
->txctl1
);
1251 if (phy
->rev
>= 6) {
1252 bcm43xx_phy_write(bcm
, 0x0036,
1253 (bcm43xx_phy_read(bcm
, 0x0036)
1254 & 0xF000) | (radio
->txctl2
<< 12));
1256 if (bcm
->sprom
.boardflags
& BCM43xx_BFL_PACTRL
)
1257 bcm43xx_phy_write(bcm
, 0x002E, 0x8075);
1259 bcm43xx_phy_write(bcm
, 0x002E, 0x807F);
1261 bcm43xx_phy_write(bcm
, 0x002F, 0x0101);
1263 bcm43xx_phy_write(bcm
, 0x002F, 0x0202);
1265 if (phy
->connected
) {
1266 bcm43xx_phy_lo_adjust(bcm
, 0);
1267 bcm43xx_phy_write(bcm
, 0x080F, 0x8078);
1270 if (!(bcm
->sprom
.boardflags
& BCM43xx_BFL_RSSI
)) {
1271 /* The specs state to update the NRSSI LT with
1272 * the value 0x7FFFFFFF here. I think that is some weird
1273 * compiler optimization in the original driver.
1274 * Essentially, what we do here is resetting all NRSSI LT
1275 * entries to -32 (see the limit_value() in nrssi_hw_update())
1277 bcm43xx_nrssi_hw_update(bcm
, 0xFFFF);
1278 bcm43xx_calc_nrssi_threshold(bcm
);
1279 } else if (phy
->connected
) {
1280 if (radio
->nrssi
[0] == -1000) {
1281 assert(radio
->nrssi
[1] == -1000);
1282 bcm43xx_calc_nrssi_slope(bcm
);
1284 assert(radio
->nrssi
[1] != -1000);
1285 bcm43xx_calc_nrssi_threshold(bcm
);
1288 if (radio
->revision
== 8)
1289 bcm43xx_phy_write(bcm
, 0x0805, 0x3230);
1290 bcm43xx_phy_init_pctl(bcm
);
1291 if (bcm
->chip_id
== 0x4306 && bcm
->chip_package
== 2) {
1292 bcm43xx_phy_write(bcm
, 0x0429,
1293 bcm43xx_phy_read(bcm
, 0x0429) & 0xBFFF);
1294 bcm43xx_phy_write(bcm
, 0x04C3,
1295 bcm43xx_phy_read(bcm
, 0x04C3) & 0x7FFF);
1299 static u16
bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private
*bcm
)
1303 unsigned long flags
;
1305 local_irq_save(flags
);
1306 for (i
= 0; i
< 10; i
++){
1307 bcm43xx_phy_write(bcm
, 0x0015, 0xAFA0);
1309 bcm43xx_phy_write(bcm
, 0x0015, 0xEFA0);
1311 bcm43xx_phy_write(bcm
, 0x0015, 0xFFA0);
1313 ret
+= bcm43xx_phy_read(bcm
, 0x002C);
1315 local_irq_restore(flags
);
1316 bcm43xx_voluntary_preempt();
1321 void bcm43xx_phy_lo_b_measure(struct bcm43xx_private
*bcm
)
1323 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
1324 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1325 u16 regstack
[12] = { 0 };
1330 regstack
[0] = bcm43xx_phy_read(bcm
, 0x0015);
1331 regstack
[1] = bcm43xx_radio_read16(bcm
, 0x0052) & 0xFFF0;
1333 if (radio
->version
== 0x2053) {
1334 regstack
[2] = bcm43xx_phy_read(bcm
, 0x000A);
1335 regstack
[3] = bcm43xx_phy_read(bcm
, 0x002A);
1336 regstack
[4] = bcm43xx_phy_read(bcm
, 0x0035);
1337 regstack
[5] = bcm43xx_phy_read(bcm
, 0x0003);
1338 regstack
[6] = bcm43xx_phy_read(bcm
, 0x0001);
1339 regstack
[7] = bcm43xx_phy_read(bcm
, 0x0030);
1341 regstack
[8] = bcm43xx_radio_read16(bcm
, 0x0043);
1342 regstack
[9] = bcm43xx_radio_read16(bcm
, 0x007A);
1343 regstack
[10] = bcm43xx_read16(bcm
, 0x03EC);
1344 regstack
[11] = bcm43xx_radio_read16(bcm
, 0x0052) & 0x00F0;
1346 bcm43xx_phy_write(bcm
, 0x0030, 0x00FF);
1347 bcm43xx_write16(bcm
, 0x03EC, 0x3F3F);
1348 bcm43xx_phy_write(bcm
, 0x0035, regstack
[4] & 0xFF7F);
1349 bcm43xx_radio_write16(bcm
, 0x007A, regstack
[9] & 0xFFF0);
1351 bcm43xx_phy_write(bcm
, 0x0015, 0xB000);
1352 bcm43xx_phy_write(bcm
, 0x002B, 0x0004);
1354 if (radio
->version
== 0x2053) {
1355 bcm43xx_phy_write(bcm
, 0x002B, 0x0203);
1356 bcm43xx_phy_write(bcm
, 0x002A, 0x08A3);
1359 phy
->minlowsig
[0] = 0xFFFF;
1361 for (i
= 0; i
< 4; i
++) {
1362 bcm43xx_radio_write16(bcm
, 0x0052, regstack
[1] | i
);
1363 bcm43xx_phy_lo_b_r15_loop(bcm
);
1365 for (i
= 0; i
< 10; i
++) {
1366 bcm43xx_radio_write16(bcm
, 0x0052, regstack
[1] | i
);
1367 mls
= bcm43xx_phy_lo_b_r15_loop(bcm
) / 10;
1368 if (mls
< phy
->minlowsig
[0]) {
1369 phy
->minlowsig
[0] = mls
;
1370 phy
->minlowsigpos
[0] = i
;
1373 bcm43xx_radio_write16(bcm
, 0x0052, regstack
[1] | phy
->minlowsigpos
[0]);
1375 phy
->minlowsig
[1] = 0xFFFF;
1377 for (i
= -4; i
< 5; i
+= 2) {
1378 for (j
= -4; j
< 5; j
+= 2) {
1380 fval
= (0x0100 * i
) + j
+ 0x0100;
1382 fval
= (0x0100 * i
) + j
;
1383 bcm43xx_phy_write(bcm
, 0x002F, fval
);
1384 mls
= bcm43xx_phy_lo_b_r15_loop(bcm
) / 10;
1385 if (mls
< phy
->minlowsig
[1]) {
1386 phy
->minlowsig
[1] = mls
;
1387 phy
->minlowsigpos
[1] = fval
;
1391 phy
->minlowsigpos
[1] += 0x0101;
1393 bcm43xx_phy_write(bcm
, 0x002F, phy
->minlowsigpos
[1]);
1394 if (radio
->version
== 0x2053) {
1395 bcm43xx_phy_write(bcm
, 0x000A, regstack
[2]);
1396 bcm43xx_phy_write(bcm
, 0x002A, regstack
[3]);
1397 bcm43xx_phy_write(bcm
, 0x0035, regstack
[4]);
1398 bcm43xx_phy_write(bcm
, 0x0003, regstack
[5]);
1399 bcm43xx_phy_write(bcm
, 0x0001, regstack
[6]);
1400 bcm43xx_phy_write(bcm
, 0x0030, regstack
[7]);
1402 bcm43xx_radio_write16(bcm
, 0x0043, regstack
[8]);
1403 bcm43xx_radio_write16(bcm
, 0x007A, regstack
[9]);
1405 bcm43xx_radio_write16(bcm
, 0x0052,
1406 (bcm43xx_radio_read16(bcm
, 0x0052) & 0x000F)
1409 bcm43xx_write16(bcm
, 0x03EC, regstack
[10]);
1411 bcm43xx_phy_write(bcm
, 0x0015, regstack
[0]);
1415 u16
bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private
*bcm
, u16 control
)
1417 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1419 unsigned long flags
;
1421 local_irq_save(flags
);
1422 if (phy
->connected
) {
1423 bcm43xx_phy_write(bcm
, 0x15, 0xE300);
1425 bcm43xx_phy_write(bcm
, 0x0812, control
| 0x00B0);
1427 bcm43xx_phy_write(bcm
, 0x0812, control
| 0x00B2);
1429 bcm43xx_phy_write(bcm
, 0x0812, control
| 0x00B3);
1431 bcm43xx_phy_write(bcm
, 0x0015, 0xF300);
1434 bcm43xx_phy_write(bcm
, 0x0015, control
| 0xEFA0);
1436 bcm43xx_phy_write(bcm
, 0x0015, control
| 0xEFE0);
1438 bcm43xx_phy_write(bcm
, 0x0015, control
| 0xFFE0);
1441 ret
= bcm43xx_phy_read(bcm
, 0x002D);
1442 local_irq_restore(flags
);
1443 bcm43xx_voluntary_preempt();
1448 static u32
bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private
*bcm
, u16 control
)
1453 for (i
= 0; i
< 8; i
++)
1454 ret
+= bcm43xx_phy_lo_g_deviation_subval(bcm
, control
);
1459 /* Write the LocalOscillator CONTROL */
1461 void bcm43xx_lo_write(struct bcm43xx_private
*bcm
,
1462 struct bcm43xx_lopair
*pair
)
1466 value
= (u8
)(pair
->low
);
1467 value
|= ((u8
)(pair
->high
)) << 8;
1469 #ifdef CONFIG_BCM43XX_DEBUG
1471 if (pair
->low
< -8 || pair
->low
> 8 ||
1472 pair
->high
< -8 || pair
->high
> 8) {
1473 printk(KERN_WARNING PFX
1474 "WARNING: Writing invalid LOpair "
1475 "(low: %d, high: %d, index: %lu)\n",
1476 pair
->low
, pair
->high
,
1477 (unsigned long)(pair
- bcm43xx_current_phy(bcm
)->_lo_pairs
));
1482 bcm43xx_phy_write(bcm
, BCM43xx_PHY_G_LO_CONTROL
, value
);
1486 struct bcm43xx_lopair
* bcm43xx_find_lopair(struct bcm43xx_private
*bcm
,
1487 u16 baseband_attenuation
,
1488 u16 radio_attenuation
,
1491 static const u8 dict
[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
1492 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1494 if (baseband_attenuation
> 6)
1495 baseband_attenuation
= 6;
1496 assert(radio_attenuation
< 10);
1499 return bcm43xx_get_lopair(phy
,
1501 baseband_attenuation
);
1503 return bcm43xx_get_lopair(phy
, dict
[radio_attenuation
], baseband_attenuation
);
1507 struct bcm43xx_lopair
* bcm43xx_current_lopair(struct bcm43xx_private
*bcm
)
1509 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
1511 return bcm43xx_find_lopair(bcm
,
1512 radio
->baseband_atten
,
1518 void bcm43xx_phy_lo_adjust(struct bcm43xx_private
*bcm
, int fixed
)
1520 struct bcm43xx_lopair
*pair
;
1523 /* Use fixed values. Only for initialization. */
1524 pair
= bcm43xx_find_lopair(bcm
, 2, 3, 0);
1526 pair
= bcm43xx_current_lopair(bcm
);
1527 bcm43xx_lo_write(bcm
, pair
);
1530 static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private
*bcm
)
1532 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
1536 bcm43xx_radio_write16(bcm
, 0x0052, 0x0000);
1538 smallest
= bcm43xx_phy_lo_g_singledeviation(bcm
, 0);
1539 for (i
= 0; i
< 16; i
++) {
1540 bcm43xx_radio_write16(bcm
, 0x0052, i
);
1542 tmp
= bcm43xx_phy_lo_g_singledeviation(bcm
, 0);
1543 if (tmp
< smallest
) {
1548 radio
->txctl2
= txctl2
;
1552 void bcm43xx_phy_lo_g_state(struct bcm43xx_private
*bcm
,
1553 const struct bcm43xx_lopair
*in_pair
,
1554 struct bcm43xx_lopair
*out_pair
,
1557 static const struct bcm43xx_lopair transitions
[8] = {
1558 { .high
= 1, .low
= 1, },
1559 { .high
= 1, .low
= 0, },
1560 { .high
= 1, .low
= -1, },
1561 { .high
= 0, .low
= -1, },
1562 { .high
= -1, .low
= -1, },
1563 { .high
= -1, .low
= 0, },
1564 { .high
= -1, .low
= 1, },
1565 { .high
= 0, .low
= 1, },
1567 struct bcm43xx_lopair lowest_transition
= {
1568 .high
= in_pair
->high
,
1569 .low
= in_pair
->low
,
1571 struct bcm43xx_lopair tmp_pair
;
1572 struct bcm43xx_lopair transition
;
1577 u32 lowest_deviation
;
1580 /* Note that in_pair and out_pair can point to the same pair. Be careful. */
1582 bcm43xx_lo_write(bcm
, &lowest_transition
);
1583 lowest_deviation
= bcm43xx_phy_lo_g_singledeviation(bcm
, r27
);
1586 assert(state
>= 0 && state
<= 8);
1590 } else if (state
% 2 == 0) {
1603 tmp_pair
.high
= lowest_transition
.high
;
1604 tmp_pair
.low
= lowest_transition
.low
;
1606 assert(j
>= 1 && j
<= 8);
1607 transition
.high
= tmp_pair
.high
+ transitions
[j
- 1].high
;
1608 transition
.low
= tmp_pair
.low
+ transitions
[j
- 1].low
;
1609 if ((abs(transition
.low
) < 9) && (abs(transition
.high
) < 9)) {
1610 bcm43xx_lo_write(bcm
, &transition
);
1611 tmp
= bcm43xx_phy_lo_g_singledeviation(bcm
, r27
);
1612 if (tmp
< lowest_deviation
) {
1613 lowest_deviation
= tmp
;
1617 lowest_transition
.high
= transition
.high
;
1618 lowest_transition
.low
= transition
.low
;
1628 } while (i
-- && found_lower
);
1630 out_pair
->high
= lowest_transition
.high
;
1631 out_pair
->low
= lowest_transition
.low
;
1634 /* Set the baseband attenuation value on chip. */
1635 void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private
*bcm
,
1636 u16 baseband_attenuation
)
1638 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1641 if (phy
->version
== 0) {
1642 value
= (bcm43xx_read16(bcm
, 0x03E6) & 0xFFF0);
1643 value
|= (baseband_attenuation
& 0x000F);
1644 bcm43xx_write16(bcm
, 0x03E6, value
);
1648 if (phy
->version
> 1) {
1649 value
= bcm43xx_phy_read(bcm
, 0x0060) & ~0x003C;
1650 value
|= (baseband_attenuation
<< 2) & 0x003C;
1652 value
= bcm43xx_phy_read(bcm
, 0x0060) & ~0x0078;
1653 value
|= (baseband_attenuation
<< 3) & 0x0078;
1655 bcm43xx_phy_write(bcm
, 0x0060, value
);
1658 /* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
1659 void bcm43xx_phy_lo_g_measure(struct bcm43xx_private
*bcm
)
1661 static const u8 pairorder
[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
1662 const int is_initializing
= (bcm43xx_status(bcm
) == BCM43xx_STAT_INITIALIZING
);
1663 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1664 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
1665 u16 h
, i
, oldi
= 0, j
;
1666 struct bcm43xx_lopair control
;
1667 struct bcm43xx_lopair
*tmp_control
;
1669 u16 regstack
[16] = { 0 };
1672 //XXX: What are these?
1675 oldchannel
= radio
->channel
;
1677 if (phy
->connected
) {
1678 regstack
[0] = bcm43xx_phy_read(bcm
, BCM43xx_PHY_G_CRS
);
1679 regstack
[1] = bcm43xx_phy_read(bcm
, 0x0802);
1680 bcm43xx_phy_write(bcm
, BCM43xx_PHY_G_CRS
, regstack
[0] & 0x7FFF);
1681 bcm43xx_phy_write(bcm
, 0x0802, regstack
[1] & 0xFFFC);
1683 regstack
[3] = bcm43xx_read16(bcm
, 0x03E2);
1684 bcm43xx_write16(bcm
, 0x03E2, regstack
[3] | 0x8000);
1685 regstack
[4] = bcm43xx_read16(bcm
, BCM43xx_MMIO_CHANNEL_EXT
);
1686 regstack
[5] = bcm43xx_phy_read(bcm
, 0x15);
1687 regstack
[6] = bcm43xx_phy_read(bcm
, 0x2A);
1688 regstack
[7] = bcm43xx_phy_read(bcm
, 0x35);
1689 regstack
[8] = bcm43xx_phy_read(bcm
, 0x60);
1690 regstack
[9] = bcm43xx_radio_read16(bcm
, 0x43);
1691 regstack
[10] = bcm43xx_radio_read16(bcm
, 0x7A);
1692 regstack
[11] = bcm43xx_radio_read16(bcm
, 0x52);
1693 if (phy
->connected
) {
1694 regstack
[12] = bcm43xx_phy_read(bcm
, 0x0811);
1695 regstack
[13] = bcm43xx_phy_read(bcm
, 0x0812);
1696 regstack
[14] = bcm43xx_phy_read(bcm
, 0x0814);
1697 regstack
[15] = bcm43xx_phy_read(bcm
, 0x0815);
1699 bcm43xx_radio_selectchannel(bcm
, 6, 0);
1700 if (phy
->connected
) {
1701 bcm43xx_phy_write(bcm
, BCM43xx_PHY_G_CRS
, regstack
[0] & 0x7FFF);
1702 bcm43xx_phy_write(bcm
, 0x0802, regstack
[1] & 0xFFFC);
1703 bcm43xx_dummy_transmission(bcm
);
1705 bcm43xx_radio_write16(bcm
, 0x0043, 0x0006);
1707 bcm43xx_phy_set_baseband_attenuation(bcm
, 2);
1709 bcm43xx_write16(bcm
, BCM43xx_MMIO_CHANNEL_EXT
, 0x0000);
1710 bcm43xx_phy_write(bcm
, 0x002E, 0x007F);
1711 bcm43xx_phy_write(bcm
, 0x080F, 0x0078);
1712 bcm43xx_phy_write(bcm
, 0x0035, regstack
[7] & ~(1 << 7));
1713 bcm43xx_radio_write16(bcm
, 0x007A, regstack
[10] & 0xFFF0);
1714 bcm43xx_phy_write(bcm
, 0x002B, 0x0203);
1715 bcm43xx_phy_write(bcm
, 0x002A, 0x08A3);
1716 if (phy
->connected
) {
1717 bcm43xx_phy_write(bcm
, 0x0814, regstack
[14] | 0x0003);
1718 bcm43xx_phy_write(bcm
, 0x0815, regstack
[15] & 0xFFFC);
1719 bcm43xx_phy_write(bcm
, 0x0811, 0x01B3);
1720 bcm43xx_phy_write(bcm
, 0x0812, 0x00B2);
1722 if (is_initializing
)
1723 bcm43xx_phy_lo_g_measure_txctl2(bcm
);
1724 bcm43xx_phy_write(bcm
, 0x080F, 0x8078);
1729 for (h
= 0; h
< 10; h
++) {
1730 /* Loop over each possible RadioAttenuation (0-9) */
1732 if (is_initializing
) {
1736 } else if (((i
% 2 == 1) && (oldi
% 2 == 1)) ||
1737 ((i
% 2 == 0) && (oldi
% 2 == 0))) {
1738 tmp_control
= bcm43xx_get_lopair(phy
, oldi
, 0);
1739 memcpy(&control
, tmp_control
, sizeof(control
));
1741 tmp_control
= bcm43xx_get_lopair(phy
, 3, 0);
1742 memcpy(&control
, tmp_control
, sizeof(control
));
1745 /* Loop over each possible BasebandAttenuation/2 */
1746 for (j
= 0; j
< 4; j
++) {
1747 if (is_initializing
) {
1759 tmp_control
= bcm43xx_get_lopair(phy
, i
, j
* 2);
1760 if (!tmp_control
->used
)
1762 memcpy(&control
, tmp_control
, sizeof(control
));
1766 bcm43xx_radio_write16(bcm
, 0x43, i
);
1767 bcm43xx_radio_write16(bcm
, 0x52, radio
->txctl2
);
1769 bcm43xx_voluntary_preempt();
1771 bcm43xx_phy_set_baseband_attenuation(bcm
, j
* 2);
1773 tmp
= (regstack
[10] & 0xFFF0);
1776 bcm43xx_radio_write16(bcm
, 0x007A, tmp
);
1778 tmp_control
= bcm43xx_get_lopair(phy
, i
, j
* 2);
1779 bcm43xx_phy_lo_g_state(bcm
, &control
, tmp_control
, r27
);
1783 /* Loop over each possible RadioAttenuation (10-13) */
1784 for (i
= 10; i
< 14; i
++) {
1785 /* Loop over each possible BasebandAttenuation/2 */
1786 for (j
= 0; j
< 4; j
++) {
1787 if (is_initializing
) {
1788 tmp_control
= bcm43xx_get_lopair(phy
, i
- 9, j
* 2);
1789 memcpy(&control
, tmp_control
, sizeof(control
));
1790 tmp
= (i
- 9) * 2 + j
- 5;//FIXME: This is wrong, as the following if statement can never trigger.
1801 tmp_control
= bcm43xx_get_lopair(phy
, i
- 9, j
* 2);
1802 if (!tmp_control
->used
)
1804 memcpy(&control
, tmp_control
, sizeof(control
));
1808 bcm43xx_radio_write16(bcm
, 0x43, i
- 9);
1809 bcm43xx_radio_write16(bcm
, 0x52,
1811 | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
1813 bcm43xx_voluntary_preempt();
1815 bcm43xx_phy_set_baseband_attenuation(bcm
, j
* 2);
1817 tmp
= (regstack
[10] & 0xFFF0);
1820 bcm43xx_radio_write16(bcm
, 0x7A, tmp
);
1822 tmp_control
= bcm43xx_get_lopair(phy
, i
, j
* 2);
1823 bcm43xx_phy_lo_g_state(bcm
, &control
, tmp_control
, r27
);
1828 if (phy
->connected
) {
1829 bcm43xx_phy_write(bcm
, 0x0015, 0xE300);
1830 bcm43xx_phy_write(bcm
, 0x0812, (r27
<< 8) | 0xA0);
1832 bcm43xx_phy_write(bcm
, 0x0812, (r27
<< 8) | 0xA2);
1834 bcm43xx_phy_write(bcm
, 0x0812, (r27
<< 8) | 0xA3);
1835 bcm43xx_voluntary_preempt();
1837 bcm43xx_phy_write(bcm
, 0x0015, r27
| 0xEFA0);
1838 bcm43xx_phy_lo_adjust(bcm
, is_initializing
);
1839 bcm43xx_phy_write(bcm
, 0x002E, 0x807F);
1841 bcm43xx_phy_write(bcm
, 0x002F, 0x0202);
1843 bcm43xx_phy_write(bcm
, 0x002F, 0x0101);
1844 bcm43xx_write16(bcm
, BCM43xx_MMIO_CHANNEL_EXT
, regstack
[4]);
1845 bcm43xx_phy_write(bcm
, 0x0015, regstack
[5]);
1846 bcm43xx_phy_write(bcm
, 0x002A, regstack
[6]);
1847 bcm43xx_phy_write(bcm
, 0x0035, regstack
[7]);
1848 bcm43xx_phy_write(bcm
, 0x0060, regstack
[8]);
1849 bcm43xx_radio_write16(bcm
, 0x0043, regstack
[9]);
1850 bcm43xx_radio_write16(bcm
, 0x007A, regstack
[10]);
1851 regstack
[11] &= 0x00F0;
1852 regstack
[11] |= (bcm43xx_radio_read16(bcm
, 0x52) & 0x000F);
1853 bcm43xx_radio_write16(bcm
, 0x52, regstack
[11]);
1854 bcm43xx_write16(bcm
, 0x03E2, regstack
[3]);
1855 if (phy
->connected
) {
1856 bcm43xx_phy_write(bcm
, 0x0811, regstack
[12]);
1857 bcm43xx_phy_write(bcm
, 0x0812, regstack
[13]);
1858 bcm43xx_phy_write(bcm
, 0x0814, regstack
[14]);
1859 bcm43xx_phy_write(bcm
, 0x0815, regstack
[15]);
1860 bcm43xx_phy_write(bcm
, BCM43xx_PHY_G_CRS
, regstack
[0]);
1861 bcm43xx_phy_write(bcm
, 0x0802, regstack
[1]);
1863 bcm43xx_radio_selectchannel(bcm
, oldchannel
, 1);
1865 #ifdef CONFIG_BCM43XX_DEBUG
1867 /* Sanity check for all lopairs. */
1868 for (i
= 0; i
< BCM43xx_LO_COUNT
; i
++) {
1869 tmp_control
= phy
->_lo_pairs
+ i
;
1870 if (tmp_control
->low
< -8 || tmp_control
->low
> 8 ||
1871 tmp_control
->high
< -8 || tmp_control
->high
> 8) {
1872 printk(KERN_WARNING PFX
1873 "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
1874 tmp_control
->low
, tmp_control
->high
, i
);
1878 #endif /* CONFIG_BCM43XX_DEBUG */
1882 void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private
*bcm
)
1884 struct bcm43xx_lopair
*pair
;
1886 pair
= bcm43xx_current_lopair(bcm
);
1890 void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private
*bcm
)
1892 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1893 struct bcm43xx_lopair
*pair
;
1896 for (i
= 0; i
< BCM43xx_LO_COUNT
; i
++) {
1897 pair
= phy
->_lo_pairs
+ i
;
1902 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1903 * This function converts a TSSI value to dBm in Q5.2
1905 static s8
bcm43xx_phy_estimate_power_out(struct bcm43xx_private
*bcm
, s8 tssi
)
1907 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1911 tmp
= phy
->idle_tssi
;
1913 tmp
-= phy
->savedpctlreg
;
1915 switch (phy
->type
) {
1916 case BCM43xx_PHYTYPE_A
:
1918 tmp
= limit_value(tmp
, 0x00, 0xFF);
1919 dbm
= phy
->tssi2dbm
[tmp
];
1920 TODO(); //TODO: There's a FIXME on the specs
1922 case BCM43xx_PHYTYPE_B
:
1923 case BCM43xx_PHYTYPE_G
:
1924 tmp
= limit_value(tmp
, 0x00, 0x3F);
1925 dbm
= phy
->tssi2dbm
[tmp
];
1934 /* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1935 void bcm43xx_phy_xmitpower(struct bcm43xx_private
*bcm
)
1937 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
1938 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
1940 if (phy
->savedpctlreg
== 0xFFFF)
1942 if ((bcm
->board_type
== 0x0416) &&
1943 (bcm
->board_vendor
== PCI_VENDOR_ID_BROADCOM
))
1946 switch (phy
->type
) {
1947 case BCM43xx_PHYTYPE_A
: {
1949 TODO(); //TODO: Nothing for A PHYs yet :-/
1953 case BCM43xx_PHYTYPE_B
:
1954 case BCM43xx_PHYTYPE_G
: {
1960 s16 desired_pwr
, estimated_pwr
, pwr_adjust
;
1961 s16 radio_att_delta
, baseband_att_delta
;
1962 s16 radio_attenuation
, baseband_attenuation
;
1963 unsigned long phylock_flags
;
1965 tmp
= bcm43xx_shm_read16(bcm
, BCM43xx_SHM_SHARED
, 0x0058);
1966 v0
= (s8
)(tmp
& 0x00FF);
1967 v1
= (s8
)((tmp
& 0xFF00) >> 8);
1968 tmp
= bcm43xx_shm_read16(bcm
, BCM43xx_SHM_SHARED
, 0x005A);
1969 v2
= (s8
)(tmp
& 0x00FF);
1970 v3
= (s8
)((tmp
& 0xFF00) >> 8);
1973 if (v0
== 0x7F || v1
== 0x7F || v2
== 0x7F || v3
== 0x7F) {
1974 tmp
= bcm43xx_shm_read16(bcm
, BCM43xx_SHM_SHARED
, 0x0070);
1975 v0
= (s8
)(tmp
& 0x00FF);
1976 v1
= (s8
)((tmp
& 0xFF00) >> 8);
1977 tmp
= bcm43xx_shm_read16(bcm
, BCM43xx_SHM_SHARED
, 0x0072);
1978 v2
= (s8
)(tmp
& 0x00FF);
1979 v3
= (s8
)((tmp
& 0xFF00) >> 8);
1980 if (v0
== 0x7F || v1
== 0x7F || v2
== 0x7F || v3
== 0x7F)
1982 v0
= (v0
+ 0x20) & 0x3F;
1983 v1
= (v1
+ 0x20) & 0x3F;
1984 v2
= (v2
+ 0x20) & 0x3F;
1985 v3
= (v3
+ 0x20) & 0x3F;
1988 bcm43xx_radio_clear_tssi(bcm
);
1990 average
= (v0
+ v1
+ v2
+ v3
+ 2) / 4;
1992 if (tmp
&& (bcm43xx_shm_read16(bcm
, BCM43xx_SHM_SHARED
, 0x005E) & 0x8))
1995 estimated_pwr
= bcm43xx_phy_estimate_power_out(bcm
, average
);
1997 max_pwr
= bcm
->sprom
.maxpower_bgphy
;
1999 if ((bcm
->sprom
.boardflags
& BCM43xx_BFL_PACTRL
) &&
2000 (phy
->type
== BCM43xx_PHYTYPE_G
))
2004 max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
2005 where REG is the max power as per the regulatory domain
2008 desired_pwr
= limit_value(radio
->txpower_desired
, 0, max_pwr
);
2009 /* Check if we need to adjust the current power. */
2010 pwr_adjust
= desired_pwr
- estimated_pwr
;
2011 radio_att_delta
= -(pwr_adjust
+ 7) >> 3;
2012 baseband_att_delta
= -(pwr_adjust
>> 1) - (4 * radio_att_delta
);
2013 if ((radio_att_delta
== 0) && (baseband_att_delta
== 0)) {
2014 bcm43xx_phy_lo_mark_current_used(bcm
);
2018 /* Calculate the new attenuation values. */
2019 baseband_attenuation
= radio
->baseband_atten
;
2020 baseband_attenuation
+= baseband_att_delta
;
2021 radio_attenuation
= radio
->radio_atten
;
2022 radio_attenuation
+= radio_att_delta
;
2024 /* Get baseband and radio attenuation values into their permitted ranges.
2025 * baseband 0-11, radio 0-9.
2026 * Radio attenuation affects power level 4 times as much as baseband.
2028 if (radio_attenuation
< 0) {
2029 baseband_attenuation
-= (4 * -radio_attenuation
);
2030 radio_attenuation
= 0;
2031 } else if (radio_attenuation
> 9) {
2032 baseband_attenuation
+= (4 * (radio_attenuation
- 9));
2033 radio_attenuation
= 9;
2035 while (baseband_attenuation
< 0 && radio_attenuation
> 0) {
2036 baseband_attenuation
+= 4;
2037 radio_attenuation
--;
2039 while (baseband_attenuation
> 11 && radio_attenuation
< 9) {
2040 baseband_attenuation
-= 4;
2041 radio_attenuation
++;
2044 baseband_attenuation
= limit_value(baseband_attenuation
, 0, 11);
2046 txpower
= radio
->txctl1
;
2047 if ((radio
->version
== 0x2050) && (radio
->revision
== 2)) {
2048 if (radio_attenuation
<= 1) {
2051 radio_attenuation
+= 2;
2052 baseband_attenuation
+= 2;
2053 } else if (bcm
->sprom
.boardflags
& BCM43xx_BFL_PACTRL
) {
2054 baseband_attenuation
+= 4 * (radio_attenuation
- 2);
2055 radio_attenuation
= 2;
2057 } else if (radio_attenuation
> 4 && txpower
!= 0) {
2059 if (baseband_attenuation
< 3) {
2060 radio_attenuation
-= 3;
2061 baseband_attenuation
+= 2;
2063 radio_attenuation
-= 2;
2064 baseband_attenuation
-= 2;
2068 radio
->txctl1
= txpower
;
2069 baseband_attenuation
= limit_value(baseband_attenuation
, 0, 11);
2070 radio_attenuation
= limit_value(radio_attenuation
, 0, 9);
2072 bcm43xx_phy_lock(bcm
, phylock_flags
);
2073 bcm43xx_radio_lock(bcm
);
2074 bcm43xx_radio_set_txpower_bg(bcm
, baseband_attenuation
,
2075 radio_attenuation
, txpower
);
2076 bcm43xx_phy_lo_mark_current_used(bcm
);
2077 bcm43xx_radio_unlock(bcm
);
2078 bcm43xx_phy_unlock(bcm
, phylock_flags
);
2087 s32
bcm43xx_tssi2dbm_ad(s32 num
, s32 den
)
2092 return (num
+den
/2)/den
;
2096 s8
bcm43xx_tssi2dbm_entry(s8 entry
[], u8 index
, s16 pab0
, s16 pab1
, s16 pab2
)
2098 s32 m1
, m2
, f
= 256, q
, delta
;
2101 m1
= bcm43xx_tssi2dbm_ad(16 * pab0
+ index
* pab1
, 32);
2102 m2
= max(bcm43xx_tssi2dbm_ad(32768 + index
* pab2
, 256), 1);
2106 q
= bcm43xx_tssi2dbm_ad(f
* 4096 -
2107 bcm43xx_tssi2dbm_ad(m2
* f
, 16) * f
, 2048);
2111 } while (delta
>= 2);
2112 entry
[index
] = limit_value(bcm43xx_tssi2dbm_ad(m1
* f
, 8192), -127, 128);
2116 /* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2117 int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private
*bcm
)
2119 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
2120 struct bcm43xx_radioinfo
*radio
= bcm43xx_current_radio(bcm
);
2121 s16 pab0
, pab1
, pab2
;
2125 if (phy
->type
== BCM43xx_PHYTYPE_A
) {
2126 pab0
= (s16
)(bcm
->sprom
.pa1b0
);
2127 pab1
= (s16
)(bcm
->sprom
.pa1b1
);
2128 pab2
= (s16
)(bcm
->sprom
.pa1b2
);
2130 pab0
= (s16
)(bcm
->sprom
.pa0b0
);
2131 pab1
= (s16
)(bcm
->sprom
.pa0b1
);
2132 pab2
= (s16
)(bcm
->sprom
.pa0b2
);
2135 if ((bcm
->chip_id
== 0x4301) && (radio
->version
!= 0x2050)) {
2136 phy
->idle_tssi
= 0x34;
2137 phy
->tssi2dbm
= bcm43xx_tssi2dbm_b_table
;
2141 if (pab0
!= 0 && pab1
!= 0 && pab2
!= 0 &&
2142 pab0
!= -1 && pab1
!= -1 && pab2
!= -1) {
2143 /* The pabX values are set in SPROM. Use them. */
2144 if (phy
->type
== BCM43xx_PHYTYPE_A
) {
2145 if ((s8
)bcm
->sprom
.idle_tssi_tgt_aphy
!= 0 &&
2146 (s8
)bcm
->sprom
.idle_tssi_tgt_aphy
!= -1)
2147 phy
->idle_tssi
= (s8
)(bcm
->sprom
.idle_tssi_tgt_aphy
);
2149 phy
->idle_tssi
= 62;
2151 if ((s8
)bcm
->sprom
.idle_tssi_tgt_bgphy
!= 0 &&
2152 (s8
)bcm
->sprom
.idle_tssi_tgt_bgphy
!= -1)
2153 phy
->idle_tssi
= (s8
)(bcm
->sprom
.idle_tssi_tgt_bgphy
);
2155 phy
->idle_tssi
= 62;
2157 dyn_tssi2dbm
= kmalloc(64, GFP_KERNEL
);
2158 if (dyn_tssi2dbm
== NULL
) {
2159 printk(KERN_ERR PFX
"Could not allocate memory"
2160 "for tssi2dbm table\n");
2163 for (idx
= 0; idx
< 64; idx
++)
2164 if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm
, idx
, pab0
, pab1
, pab2
)) {
2165 phy
->tssi2dbm
= NULL
;
2166 printk(KERN_ERR PFX
"Could not generate "
2167 "tssi2dBm table\n");
2168 kfree(dyn_tssi2dbm
);
2171 phy
->tssi2dbm
= dyn_tssi2dbm
;
2172 phy
->dyn_tssi_tbl
= 1;
2174 /* pabX values not set in SPROM. */
2175 switch (phy
->type
) {
2176 case BCM43xx_PHYTYPE_A
:
2177 /* APHY needs a generated table. */
2178 phy
->tssi2dbm
= NULL
;
2179 printk(KERN_ERR PFX
"Could not generate tssi2dBm "
2180 "table (wrong SPROM info)!\n");
2182 case BCM43xx_PHYTYPE_B
:
2183 phy
->idle_tssi
= 0x34;
2184 phy
->tssi2dbm
= bcm43xx_tssi2dbm_b_table
;
2186 case BCM43xx_PHYTYPE_G
:
2187 phy
->idle_tssi
= 0x34;
2188 phy
->tssi2dbm
= bcm43xx_tssi2dbm_g_table
;
2196 int bcm43xx_phy_init(struct bcm43xx_private
*bcm
)
2198 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
2201 switch (phy
->type
) {
2202 case BCM43xx_PHYTYPE_A
:
2203 if (phy
->rev
== 2 || phy
->rev
== 3) {
2204 bcm43xx_phy_inita(bcm
);
2208 case BCM43xx_PHYTYPE_B
:
2211 bcm43xx_phy_initb2(bcm
);
2215 bcm43xx_phy_initb4(bcm
);
2219 bcm43xx_phy_initb5(bcm
);
2223 bcm43xx_phy_initb6(bcm
);
2228 case BCM43xx_PHYTYPE_G
:
2229 bcm43xx_phy_initg(bcm
);
2234 printk(KERN_WARNING PFX
"Unknown PHYTYPE found!\n");
2239 void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private
*bcm
)
2241 struct bcm43xx_phyinfo
*phy
= bcm43xx_current_phy(bcm
);
2247 antennadiv
= phy
->antenna_diversity
;
2249 if (antennadiv
== 0xFFFF)
2251 assert(antennadiv
<= 3);
2253 ucodeflags
= bcm43xx_shm_read32(bcm
, BCM43xx_SHM_SHARED
,
2254 BCM43xx_UCODEFLAGS_OFFSET
);
2255 bcm43xx_shm_write32(bcm
, BCM43xx_SHM_SHARED
,
2256 BCM43xx_UCODEFLAGS_OFFSET
,
2257 ucodeflags
& ~BCM43xx_UCODEFLAG_AUTODIV
);
2259 switch (phy
->type
) {
2260 case BCM43xx_PHYTYPE_A
:
2261 case BCM43xx_PHYTYPE_G
:
2262 if (phy
->type
== BCM43xx_PHYTYPE_A
)
2267 if (antennadiv
== 2)
2268 value
= (3/*automatic*/ << 7);
2270 value
= (antennadiv
<< 7);
2271 bcm43xx_phy_write(bcm
, offset
+ 1,
2272 (bcm43xx_phy_read(bcm
, offset
+ 1)
2275 if (antennadiv
>= 2) {
2276 if (antennadiv
== 2)
2277 value
= (antennadiv
<< 7);
2279 value
= (0/*force0*/ << 7);
2280 bcm43xx_phy_write(bcm
, offset
+ 0x2B,
2281 (bcm43xx_phy_read(bcm
, offset
+ 0x2B)
2285 if (phy
->type
== BCM43xx_PHYTYPE_G
) {
2286 if (antennadiv
>= 2)
2287 bcm43xx_phy_write(bcm
, 0x048C,
2288 bcm43xx_phy_read(bcm
, 0x048C)
2291 bcm43xx_phy_write(bcm
, 0x048C,
2292 bcm43xx_phy_read(bcm
, 0x048C)
2294 if (phy
->rev
>= 2) {
2295 bcm43xx_phy_write(bcm
, 0x0461,
2296 bcm43xx_phy_read(bcm
, 0x0461)
2298 bcm43xx_phy_write(bcm
, 0x04AD,
2299 (bcm43xx_phy_read(bcm
, 0x04AD)
2300 & 0x00FF) | 0x0015);
2302 bcm43xx_phy_write(bcm
, 0x0427, 0x0008);
2304 bcm43xx_phy_write(bcm
, 0x0427,
2305 (bcm43xx_phy_read(bcm
, 0x0427)
2306 & 0x00FF) | 0x0008);
2308 else if (phy
->rev
>= 6)
2309 bcm43xx_phy_write(bcm
, 0x049B, 0x00DC);
2312 bcm43xx_phy_write(bcm
, 0x002B,
2313 (bcm43xx_phy_read(bcm
, 0x002B)
2314 & 0x00FF) | 0x0024);
2316 bcm43xx_phy_write(bcm
, 0x0061,
2317 bcm43xx_phy_read(bcm
, 0x0061)
2319 if (phy
->rev
== 3) {
2320 bcm43xx_phy_write(bcm
, 0x0093, 0x001D);
2321 bcm43xx_phy_write(bcm
, 0x0027, 0x0008);
2323 bcm43xx_phy_write(bcm
, 0x0093, 0x003A);
2324 bcm43xx_phy_write(bcm
, 0x0027,
2325 (bcm43xx_phy_read(bcm
, 0x0027)
2326 & 0x00FF) | 0x0008);
2331 case BCM43xx_PHYTYPE_B
:
2332 if (bcm
->current_core
->rev
== 2)
2333 value
= (3/*automatic*/ << 7);
2335 value
= (antennadiv
<< 7);
2336 bcm43xx_phy_write(bcm
, 0x03E2,
2337 (bcm43xx_phy_read(bcm
, 0x03E2)
2344 if (antennadiv
>= 2) {
2345 ucodeflags
= bcm43xx_shm_read32(bcm
, BCM43xx_SHM_SHARED
,
2346 BCM43xx_UCODEFLAGS_OFFSET
);
2347 bcm43xx_shm_write32(bcm
, BCM43xx_SHM_SHARED
,
2348 BCM43xx_UCODEFLAGS_OFFSET
,
2349 ucodeflags
| BCM43xx_UCODEFLAG_AUTODIV
);
2352 phy
->antenna_diversity
= antennadiv
;