3 Broadcom B43 wireless driver
4 IEEE 802.11g PHY driver
6 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
7 Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
8 Copyright (c) 2005-2008 Michael Buesch <m@bues.ch>
9 Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
10 Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
25 Boston, MA 02110-1301, USA.
31 #include "phy_common.h"
36 #include <linux/bitrev.h>
37 #include <linux/slab.h>
40 static const s8 b43_tssi2dbm_g_table
[] = {
59 static const u8 b43_radio_channel_codes_bg
[] = {
67 static void b43_calc_nrssi_threshold(struct b43_wldev
*dev
);
70 #define bitrev4(tmp) (bitrev8(tmp) >> 4)
73 /* Get the freq, as it has to be written to the device. */
74 static inline u16
channel2freq_bg(u8 channel
)
76 B43_WARN_ON(!(channel
>= 1 && channel
<= 14));
78 return b43_radio_channel_codes_bg
[channel
- 1];
81 static void generate_rfatt_list(struct b43_wldev
*dev
,
82 struct b43_rfatt_list
*list
)
84 struct b43_phy
*phy
= &dev
->phy
;
86 /* APHY.rev < 5 || GPHY.rev < 6 */
87 static const struct b43_rfatt rfatt_0
[] = {
88 {.att
= 3,.with_padmix
= 0,},
89 {.att
= 1,.with_padmix
= 0,},
90 {.att
= 5,.with_padmix
= 0,},
91 {.att
= 7,.with_padmix
= 0,},
92 {.att
= 9,.with_padmix
= 0,},
93 {.att
= 2,.with_padmix
= 0,},
94 {.att
= 0,.with_padmix
= 0,},
95 {.att
= 4,.with_padmix
= 0,},
96 {.att
= 6,.with_padmix
= 0,},
97 {.att
= 8,.with_padmix
= 0,},
98 {.att
= 1,.with_padmix
= 1,},
99 {.att
= 2,.with_padmix
= 1,},
100 {.att
= 3,.with_padmix
= 1,},
101 {.att
= 4,.with_padmix
= 1,},
103 /* Radio.rev == 8 && Radio.version == 0x2050 */
104 static const struct b43_rfatt rfatt_1
[] = {
105 {.att
= 2,.with_padmix
= 1,},
106 {.att
= 4,.with_padmix
= 1,},
107 {.att
= 6,.with_padmix
= 1,},
108 {.att
= 8,.with_padmix
= 1,},
109 {.att
= 10,.with_padmix
= 1,},
110 {.att
= 12,.with_padmix
= 1,},
111 {.att
= 14,.with_padmix
= 1,},
114 static const struct b43_rfatt rfatt_2
[] = {
115 {.att
= 0,.with_padmix
= 1,},
116 {.att
= 2,.with_padmix
= 1,},
117 {.att
= 4,.with_padmix
= 1,},
118 {.att
= 6,.with_padmix
= 1,},
119 {.att
= 8,.with_padmix
= 1,},
120 {.att
= 9,.with_padmix
= 1,},
121 {.att
= 9,.with_padmix
= 1,},
124 if (!b43_has_hardware_pctl(dev
)) {
126 list
->list
= rfatt_0
;
127 list
->len
= ARRAY_SIZE(rfatt_0
);
132 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
== 8) {
134 list
->list
= rfatt_1
;
135 list
->len
= ARRAY_SIZE(rfatt_1
);
141 list
->list
= rfatt_2
;
142 list
->len
= ARRAY_SIZE(rfatt_2
);
147 static void generate_bbatt_list(struct b43_wldev
*dev
,
148 struct b43_bbatt_list
*list
)
150 static const struct b43_bbatt bbatt_0
[] = {
162 list
->list
= bbatt_0
;
163 list
->len
= ARRAY_SIZE(bbatt_0
);
168 static void b43_shm_clear_tssi(struct b43_wldev
*dev
)
170 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0058, 0x7F7F);
171 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x005a, 0x7F7F);
172 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0070, 0x7F7F);
173 b43_shm_write16(dev
, B43_SHM_SHARED
, 0x0072, 0x7F7F);
176 /* Synthetic PU workaround */
177 static void b43_synth_pu_workaround(struct b43_wldev
*dev
, u8 channel
)
179 struct b43_phy
*phy
= &dev
->phy
;
183 if (phy
->radio_ver
!= 0x2050 || phy
->radio_rev
>= 6) {
184 /* We do not need the workaround. */
189 b43_write16(dev
, B43_MMIO_CHANNEL
,
190 channel2freq_bg(channel
+ 4));
192 b43_write16(dev
, B43_MMIO_CHANNEL
, channel2freq_bg(1));
195 b43_write16(dev
, B43_MMIO_CHANNEL
, channel2freq_bg(channel
));
198 /* Set the baseband attenuation value on chip. */
199 void b43_gphy_set_baseband_attenuation(struct b43_wldev
*dev
,
200 u16 baseband_attenuation
)
202 struct b43_phy
*phy
= &dev
->phy
;
204 if (phy
->analog
== 0) {
205 b43_write16(dev
, B43_MMIO_PHY0
, (b43_read16(dev
, B43_MMIO_PHY0
)
207 baseband_attenuation
);
208 } else if (phy
->analog
> 1) {
209 b43_phy_maskset(dev
, B43_PHY_DACCTL
, 0xFFC3, (baseband_attenuation
<< 2));
211 b43_phy_maskset(dev
, B43_PHY_DACCTL
, 0xFF87, (baseband_attenuation
<< 3));
215 /* Adjust the transmission power output (G-PHY) */
216 static void b43_set_txpower_g(struct b43_wldev
*dev
,
217 const struct b43_bbatt
*bbatt
,
218 const struct b43_rfatt
*rfatt
, u8 tx_control
)
220 struct b43_phy
*phy
= &dev
->phy
;
221 struct b43_phy_g
*gphy
= phy
->g
;
222 struct b43_txpower_lo_control
*lo
= gphy
->lo_control
;
224 u16 tx_bias
, tx_magn
;
228 tx_bias
= lo
->tx_bias
;
229 tx_magn
= lo
->tx_magn
;
230 if (unlikely(tx_bias
== 0xFF))
233 /* Save the values for later. Use memmove, because it's valid
234 * to pass &gphy->rfatt as rfatt pointer argument. Same for bbatt. */
235 gphy
->tx_control
= tx_control
;
236 memmove(&gphy
->rfatt
, rfatt
, sizeof(*rfatt
));
237 gphy
->rfatt
.with_padmix
= !!(tx_control
& B43_TXCTL_TXMIX
);
238 memmove(&gphy
->bbatt
, bbatt
, sizeof(*bbatt
));
240 if (b43_debug(dev
, B43_DBG_XMITPOWER
)) {
241 b43dbg(dev
->wl
, "Tuning TX-power to bbatt(%u), "
242 "rfatt(%u), tx_control(0x%02X), "
243 "tx_bias(0x%02X), tx_magn(0x%02X)\n",
244 bb
, rf
, tx_control
, tx_bias
, tx_magn
);
247 b43_gphy_set_baseband_attenuation(dev
, bb
);
248 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_RFATT
, rf
);
249 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
== 8) {
250 b43_radio_write16(dev
, 0x43,
251 (rf
& 0x000F) | (tx_control
& 0x0070));
253 b43_radio_maskset(dev
, 0x43, 0xFFF0, (rf
& 0x000F));
254 b43_radio_maskset(dev
, 0x52, ~0x0070, (tx_control
& 0x0070));
256 if (has_tx_magnification(phy
)) {
257 b43_radio_write16(dev
, 0x52, tx_magn
| tx_bias
);
259 b43_radio_maskset(dev
, 0x52, 0xFFF0, (tx_bias
& 0x000F));
261 b43_lo_g_adjust(dev
);
264 /* GPHY_TSSI_Power_Lookup_Table_Init */
265 static void b43_gphy_tssi_power_lt_init(struct b43_wldev
*dev
)
267 struct b43_phy_g
*gphy
= dev
->phy
.g
;
271 for (i
= 0; i
< 32; i
++)
272 b43_ofdmtab_write16(dev
, 0x3C20, i
, gphy
->tssi2dbm
[i
]);
273 for (i
= 32; i
< 64; i
++)
274 b43_ofdmtab_write16(dev
, 0x3C00, i
- 32, gphy
->tssi2dbm
[i
]);
275 for (i
= 0; i
< 64; i
+= 2) {
276 value
= (u16
) gphy
->tssi2dbm
[i
];
277 value
|= ((u16
) gphy
->tssi2dbm
[i
+ 1]) << 8;
278 b43_phy_write(dev
, 0x380 + (i
/ 2), value
);
282 /* GPHY_Gain_Lookup_Table_Init */
283 static void b43_gphy_gain_lt_init(struct b43_wldev
*dev
)
285 struct b43_phy
*phy
= &dev
->phy
;
286 struct b43_phy_g
*gphy
= phy
->g
;
287 struct b43_txpower_lo_control
*lo
= gphy
->lo_control
;
292 for (rf
= 0; rf
< lo
->rfatt_list
.len
; rf
++) {
293 for (bb
= 0; bb
< lo
->bbatt_list
.len
; bb
++) {
294 if (nr_written
>= 0x40)
296 tmp
= lo
->bbatt_list
.list
[bb
].att
;
298 if (phy
->radio_rev
== 8)
302 tmp
|= lo
->rfatt_list
.list
[rf
].att
;
303 b43_phy_write(dev
, 0x3C0 + nr_written
, tmp
);
309 static void b43_set_all_gains(struct b43_wldev
*dev
,
310 s16 first
, s16 second
, s16 third
)
312 struct b43_phy
*phy
= &dev
->phy
;
314 u16 start
= 0x08, end
= 0x18;
323 table
= B43_OFDMTAB_GAINX
;
325 table
= B43_OFDMTAB_GAINX_R1
;
326 for (i
= 0; i
< 4; i
++)
327 b43_ofdmtab_write16(dev
, table
, i
, first
);
329 for (i
= start
; i
< end
; i
++)
330 b43_ofdmtab_write16(dev
, table
, i
, second
);
333 tmp
= ((u16
) third
<< 14) | ((u16
) third
<< 6);
334 b43_phy_maskset(dev
, 0x04A0, 0xBFBF, tmp
);
335 b43_phy_maskset(dev
, 0x04A1, 0xBFBF, tmp
);
336 b43_phy_maskset(dev
, 0x04A2, 0xBFBF, tmp
);
338 b43_dummy_transmission(dev
, false, true);
341 static void b43_set_original_gains(struct b43_wldev
*dev
)
343 struct b43_phy
*phy
= &dev
->phy
;
346 u16 start
= 0x0008, end
= 0x0018;
353 table
= B43_OFDMTAB_GAINX
;
355 table
= B43_OFDMTAB_GAINX_R1
;
356 for (i
= 0; i
< 4; i
++) {
358 tmp
|= (i
& 0x0001) << 1;
359 tmp
|= (i
& 0x0002) >> 1;
361 b43_ofdmtab_write16(dev
, table
, i
, tmp
);
364 for (i
= start
; i
< end
; i
++)
365 b43_ofdmtab_write16(dev
, table
, i
, i
- start
);
367 b43_phy_maskset(dev
, 0x04A0, 0xBFBF, 0x4040);
368 b43_phy_maskset(dev
, 0x04A1, 0xBFBF, 0x4040);
369 b43_phy_maskset(dev
, 0x04A2, 0xBFBF, 0x4000);
370 b43_dummy_transmission(dev
, false, true);
373 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
374 static void b43_nrssi_hw_write(struct b43_wldev
*dev
, u16 offset
, s16 val
)
376 b43_phy_write(dev
, B43_PHY_NRSSILT_CTRL
, offset
);
377 b43_phy_write(dev
, B43_PHY_NRSSILT_DATA
, (u16
) val
);
380 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
381 static s16
b43_nrssi_hw_read(struct b43_wldev
*dev
, u16 offset
)
385 b43_phy_write(dev
, B43_PHY_NRSSILT_CTRL
, offset
);
386 val
= b43_phy_read(dev
, B43_PHY_NRSSILT_DATA
);
391 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
392 static void b43_nrssi_hw_update(struct b43_wldev
*dev
, u16 val
)
397 for (i
= 0; i
< 64; i
++) {
398 tmp
= b43_nrssi_hw_read(dev
, i
);
400 tmp
= clamp_val(tmp
, -32, 31);
401 b43_nrssi_hw_write(dev
, i
, tmp
);
405 /* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
406 static void b43_nrssi_mem_update(struct b43_wldev
*dev
)
408 struct b43_phy_g
*gphy
= dev
->phy
.g
;
412 delta
= 0x1F - gphy
->nrssi
[0];
413 for (i
= 0; i
< 64; i
++) {
414 tmp
= (i
- delta
) * gphy
->nrssislope
;
417 tmp
= clamp_val(tmp
, 0, 0x3F);
418 gphy
->nrssi_lt
[i
] = tmp
;
422 static void b43_calc_nrssi_offset(struct b43_wldev
*dev
)
424 struct b43_phy
*phy
= &dev
->phy
;
425 u16 backup
[20] = { 0 };
430 backup
[0] = b43_phy_read(dev
, 0x0001);
431 backup
[1] = b43_phy_read(dev
, 0x0811);
432 backup
[2] = b43_phy_read(dev
, 0x0812);
433 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
434 backup
[3] = b43_phy_read(dev
, 0x0814);
435 backup
[4] = b43_phy_read(dev
, 0x0815);
437 backup
[5] = b43_phy_read(dev
, 0x005A);
438 backup
[6] = b43_phy_read(dev
, 0x0059);
439 backup
[7] = b43_phy_read(dev
, 0x0058);
440 backup
[8] = b43_phy_read(dev
, 0x000A);
441 backup
[9] = b43_phy_read(dev
, 0x0003);
442 backup
[10] = b43_radio_read16(dev
, 0x007A);
443 backup
[11] = b43_radio_read16(dev
, 0x0043);
445 b43_phy_mask(dev
, 0x0429, 0x7FFF);
446 b43_phy_maskset(dev
, 0x0001, 0x3FFF, 0x4000);
447 b43_phy_set(dev
, 0x0811, 0x000C);
448 b43_phy_maskset(dev
, 0x0812, 0xFFF3, 0x0004);
449 b43_phy_mask(dev
, 0x0802, ~(0x1 | 0x2));
451 backup
[12] = b43_phy_read(dev
, 0x002E);
452 backup
[13] = b43_phy_read(dev
, 0x002F);
453 backup
[14] = b43_phy_read(dev
, 0x080F);
454 backup
[15] = b43_phy_read(dev
, 0x0810);
455 backup
[16] = b43_phy_read(dev
, 0x0801);
456 backup
[17] = b43_phy_read(dev
, 0x0060);
457 backup
[18] = b43_phy_read(dev
, 0x0014);
458 backup
[19] = b43_phy_read(dev
, 0x0478);
460 b43_phy_write(dev
, 0x002E, 0);
461 b43_phy_write(dev
, 0x002F, 0);
462 b43_phy_write(dev
, 0x080F, 0);
463 b43_phy_write(dev
, 0x0810, 0);
464 b43_phy_set(dev
, 0x0478, 0x0100);
465 b43_phy_set(dev
, 0x0801, 0x0040);
466 b43_phy_set(dev
, 0x0060, 0x0040);
467 b43_phy_set(dev
, 0x0014, 0x0200);
469 b43_radio_set(dev
, 0x007A, 0x0070);
470 b43_radio_set(dev
, 0x007A, 0x0080);
473 v47F
= (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) & 0x003F);
477 for (i
= 7; i
>= 4; i
--) {
478 b43_radio_write16(dev
, 0x007B, i
);
481 (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) & 0x003F);
484 if (v47F
< 31 && saved
== 0xFFFF)
490 b43_radio_mask(dev
, 0x007A, 0x007F);
491 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
492 b43_phy_set(dev
, 0x0814, 0x0001);
493 b43_phy_mask(dev
, 0x0815, 0xFFFE);
495 b43_phy_set(dev
, 0x0811, 0x000C);
496 b43_phy_set(dev
, 0x0812, 0x000C);
497 b43_phy_set(dev
, 0x0811, 0x0030);
498 b43_phy_set(dev
, 0x0812, 0x0030);
499 b43_phy_write(dev
, 0x005A, 0x0480);
500 b43_phy_write(dev
, 0x0059, 0x0810);
501 b43_phy_write(dev
, 0x0058, 0x000D);
503 b43_phy_write(dev
, 0x0003, 0x0122);
505 b43_phy_set(dev
, 0x000A, 0x2000);
507 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
508 b43_phy_set(dev
, 0x0814, 0x0004);
509 b43_phy_mask(dev
, 0x0815, 0xFFFB);
511 b43_phy_maskset(dev
, 0x0003, 0xFF9F, 0x0040);
512 b43_radio_set(dev
, 0x007A, 0x000F);
513 b43_set_all_gains(dev
, 3, 0, 1);
514 b43_radio_maskset(dev
, 0x0043, 0x00F0, 0x000F);
516 v47F
= (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) & 0x003F);
520 for (i
= 0; i
< 4; i
++) {
521 b43_radio_write16(dev
, 0x007B, i
);
524 (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) &
528 if (v47F
> -31 && saved
== 0xFFFF)
536 b43_radio_write16(dev
, 0x007B, saved
);
539 b43_phy_write(dev
, 0x002E, backup
[12]);
540 b43_phy_write(dev
, 0x002F, backup
[13]);
541 b43_phy_write(dev
, 0x080F, backup
[14]);
542 b43_phy_write(dev
, 0x0810, backup
[15]);
544 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
545 b43_phy_write(dev
, 0x0814, backup
[3]);
546 b43_phy_write(dev
, 0x0815, backup
[4]);
548 b43_phy_write(dev
, 0x005A, backup
[5]);
549 b43_phy_write(dev
, 0x0059, backup
[6]);
550 b43_phy_write(dev
, 0x0058, backup
[7]);
551 b43_phy_write(dev
, 0x000A, backup
[8]);
552 b43_phy_write(dev
, 0x0003, backup
[9]);
553 b43_radio_write16(dev
, 0x0043, backup
[11]);
554 b43_radio_write16(dev
, 0x007A, backup
[10]);
555 b43_phy_write(dev
, 0x0802, b43_phy_read(dev
, 0x0802) | 0x1 | 0x2);
556 b43_phy_set(dev
, 0x0429, 0x8000);
557 b43_set_original_gains(dev
);
559 b43_phy_write(dev
, 0x0801, backup
[16]);
560 b43_phy_write(dev
, 0x0060, backup
[17]);
561 b43_phy_write(dev
, 0x0014, backup
[18]);
562 b43_phy_write(dev
, 0x0478, backup
[19]);
564 b43_phy_write(dev
, 0x0001, backup
[0]);
565 b43_phy_write(dev
, 0x0812, backup
[2]);
566 b43_phy_write(dev
, 0x0811, backup
[1]);
569 static void b43_calc_nrssi_slope(struct b43_wldev
*dev
)
571 struct b43_phy
*phy
= &dev
->phy
;
572 struct b43_phy_g
*gphy
= phy
->g
;
573 u16 backup
[18] = { 0 };
577 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
579 if (phy
->radio_rev
>= 9)
581 if (phy
->radio_rev
== 8)
582 b43_calc_nrssi_offset(dev
);
584 b43_phy_mask(dev
, B43_PHY_G_CRS
, 0x7FFF);
585 b43_phy_mask(dev
, 0x0802, 0xFFFC);
586 backup
[7] = b43_read16(dev
, 0x03E2);
587 b43_write16(dev
, 0x03E2, b43_read16(dev
, 0x03E2) | 0x8000);
588 backup
[0] = b43_radio_read16(dev
, 0x007A);
589 backup
[1] = b43_radio_read16(dev
, 0x0052);
590 backup
[2] = b43_radio_read16(dev
, 0x0043);
591 backup
[3] = b43_phy_read(dev
, 0x0015);
592 backup
[4] = b43_phy_read(dev
, 0x005A);
593 backup
[5] = b43_phy_read(dev
, 0x0059);
594 backup
[6] = b43_phy_read(dev
, 0x0058);
595 backup
[8] = b43_read16(dev
, 0x03E6);
596 backup
[9] = b43_read16(dev
, B43_MMIO_CHANNEL_EXT
);
598 backup
[10] = b43_phy_read(dev
, 0x002E);
599 backup
[11] = b43_phy_read(dev
, 0x002F);
600 backup
[12] = b43_phy_read(dev
, 0x080F);
601 backup
[13] = b43_phy_read(dev
, B43_PHY_G_LO_CONTROL
);
602 backup
[14] = b43_phy_read(dev
, 0x0801);
603 backup
[15] = b43_phy_read(dev
, 0x0060);
604 backup
[16] = b43_phy_read(dev
, 0x0014);
605 backup
[17] = b43_phy_read(dev
, 0x0478);
606 b43_phy_write(dev
, 0x002E, 0);
607 b43_phy_write(dev
, B43_PHY_G_LO_CONTROL
, 0);
612 b43_phy_set(dev
, 0x0478, 0x0100);
613 b43_phy_set(dev
, 0x0801, 0x0040);
617 b43_phy_mask(dev
, 0x0801, 0xFFBF);
620 b43_phy_set(dev
, 0x0060, 0x0040);
621 b43_phy_set(dev
, 0x0014, 0x0200);
623 b43_radio_set(dev
, 0x007A, 0x0070);
624 b43_set_all_gains(dev
, 0, 8, 0);
625 b43_radio_mask(dev
, 0x007A, 0x00F7);
627 b43_phy_maskset(dev
, 0x0811, 0xFFCF, 0x0030);
628 b43_phy_maskset(dev
, 0x0812, 0xFFCF, 0x0010);
630 b43_radio_set(dev
, 0x007A, 0x0080);
633 nrssi0
= (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) & 0x003F);
634 if (nrssi0
>= 0x0020)
637 b43_radio_mask(dev
, 0x007A, 0x007F);
639 b43_phy_maskset(dev
, 0x0003, 0xFF9F, 0x0040);
642 b43_write16(dev
, B43_MMIO_CHANNEL_EXT
,
643 b43_read16(dev
, B43_MMIO_CHANNEL_EXT
)
645 b43_radio_set(dev
, 0x007A, 0x000F);
646 b43_phy_write(dev
, 0x0015, 0xF330);
648 b43_phy_maskset(dev
, 0x0812, 0xFFCF, 0x0020);
649 b43_phy_maskset(dev
, 0x0811, 0xFFCF, 0x0020);
652 b43_set_all_gains(dev
, 3, 0, 1);
653 if (phy
->radio_rev
== 8) {
654 b43_radio_write16(dev
, 0x0043, 0x001F);
656 tmp
= b43_radio_read16(dev
, 0x0052) & 0xFF0F;
657 b43_radio_write16(dev
, 0x0052, tmp
| 0x0060);
658 tmp
= b43_radio_read16(dev
, 0x0043) & 0xFFF0;
659 b43_radio_write16(dev
, 0x0043, tmp
| 0x0009);
661 b43_phy_write(dev
, 0x005A, 0x0480);
662 b43_phy_write(dev
, 0x0059, 0x0810);
663 b43_phy_write(dev
, 0x0058, 0x000D);
665 nrssi1
= (s16
) ((b43_phy_read(dev
, 0x047F) >> 8) & 0x003F);
666 if (nrssi1
>= 0x0020)
668 if (nrssi0
== nrssi1
)
669 gphy
->nrssislope
= 0x00010000;
671 gphy
->nrssislope
= 0x00400000 / (nrssi0
- nrssi1
);
673 gphy
->nrssi
[0] = nrssi1
;
674 gphy
->nrssi
[1] = nrssi0
;
677 b43_phy_write(dev
, 0x002E, backup
[10]);
678 b43_phy_write(dev
, 0x002F, backup
[11]);
679 b43_phy_write(dev
, 0x080F, backup
[12]);
680 b43_phy_write(dev
, B43_PHY_G_LO_CONTROL
, backup
[13]);
683 b43_phy_mask(dev
, 0x0812, 0xFFCF);
684 b43_phy_mask(dev
, 0x0811, 0xFFCF);
687 b43_radio_write16(dev
, 0x007A, backup
[0]);
688 b43_radio_write16(dev
, 0x0052, backup
[1]);
689 b43_radio_write16(dev
, 0x0043, backup
[2]);
690 b43_write16(dev
, 0x03E2, backup
[7]);
691 b43_write16(dev
, 0x03E6, backup
[8]);
692 b43_write16(dev
, B43_MMIO_CHANNEL_EXT
, backup
[9]);
693 b43_phy_write(dev
, 0x0015, backup
[3]);
694 b43_phy_write(dev
, 0x005A, backup
[4]);
695 b43_phy_write(dev
, 0x0059, backup
[5]);
696 b43_phy_write(dev
, 0x0058, backup
[6]);
697 b43_synth_pu_workaround(dev
, phy
->channel
);
698 b43_phy_set(dev
, 0x0802, (0x0001 | 0x0002));
699 b43_set_original_gains(dev
);
700 b43_phy_set(dev
, B43_PHY_G_CRS
, 0x8000);
702 b43_phy_write(dev
, 0x0801, backup
[14]);
703 b43_phy_write(dev
, 0x0060, backup
[15]);
704 b43_phy_write(dev
, 0x0014, backup
[16]);
705 b43_phy_write(dev
, 0x0478, backup
[17]);
707 b43_nrssi_mem_update(dev
);
708 b43_calc_nrssi_threshold(dev
);
711 static void b43_calc_nrssi_threshold(struct b43_wldev
*dev
)
713 struct b43_phy
*phy
= &dev
->phy
;
714 struct b43_phy_g
*gphy
= phy
->g
;
719 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
722 !(dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_RSSI
)) {
723 tmp16
= b43_nrssi_hw_read(dev
, 0x20);
727 b43_phy_maskset(dev
, 0x048A, 0xF000, 0x09EB);
729 b43_phy_maskset(dev
, 0x048A, 0xF000, 0x0AED);
732 if (gphy
->interfmode
== B43_INTERFMODE_NONWLAN
) {
735 } else if (!gphy
->aci_wlan_automatic
&& gphy
->aci_enable
) {
743 a
= a
* (gphy
->nrssi
[1] - gphy
->nrssi
[0]);
744 a
+= (gphy
->nrssi
[0] << 6);
750 a
= clamp_val(a
, -31, 31);
752 b
= b
* (gphy
->nrssi
[1] - gphy
->nrssi
[0]);
753 b
+= (gphy
->nrssi
[0] << 6);
759 b
= clamp_val(b
, -31, 31);
761 tmp_u16
= b43_phy_read(dev
, 0x048A) & 0xF000;
762 tmp_u16
|= ((u32
) b
& 0x0000003F);
763 tmp_u16
|= (((u32
) a
& 0x0000003F) << 6);
764 b43_phy_write(dev
, 0x048A, tmp_u16
);
768 /* Stack implementation to save/restore values from the
769 * interference mitigation code.
770 * It is save to restore values in random order.
772 static void _stack_save(u32
*_stackptr
, size_t *stackidx
,
773 u8 id
, u16 offset
, u16 value
)
775 u32
*stackptr
= &(_stackptr
[*stackidx
]);
777 B43_WARN_ON(offset
& 0xF000);
778 B43_WARN_ON(id
& 0xF0);
780 *stackptr
|= ((u32
) id
) << 12;
781 *stackptr
|= ((u32
) value
) << 16;
783 B43_WARN_ON(*stackidx
>= B43_INTERFSTACK_SIZE
);
786 static u16
_stack_restore(u32
*stackptr
, u8 id
, u16 offset
)
790 B43_WARN_ON(offset
& 0xF000);
791 B43_WARN_ON(id
& 0xF0);
792 for (i
= 0; i
< B43_INTERFSTACK_SIZE
; i
++, stackptr
++) {
793 if ((*stackptr
& 0x00000FFF) != offset
)
795 if (((*stackptr
& 0x0000F000) >> 12) != id
)
797 return ((*stackptr
& 0xFFFF0000) >> 16);
804 #define phy_stacksave(offset) \
806 _stack_save(stack, &stackidx, 0x1, (offset), \
807 b43_phy_read(dev, (offset))); \
809 #define phy_stackrestore(offset) \
811 b43_phy_write(dev, (offset), \
812 _stack_restore(stack, 0x1, \
815 #define radio_stacksave(offset) \
817 _stack_save(stack, &stackidx, 0x2, (offset), \
818 b43_radio_read16(dev, (offset))); \
820 #define radio_stackrestore(offset) \
822 b43_radio_write16(dev, (offset), \
823 _stack_restore(stack, 0x2, \
826 #define ofdmtab_stacksave(table, offset) \
828 _stack_save(stack, &stackidx, 0x3, (offset)|(table), \
829 b43_ofdmtab_read16(dev, (table), (offset))); \
831 #define ofdmtab_stackrestore(table, offset) \
833 b43_ofdmtab_write16(dev, (table), (offset), \
834 _stack_restore(stack, 0x3, \
835 (offset)|(table))); \
839 b43_radio_interference_mitigation_enable(struct b43_wldev
*dev
, int mode
)
841 struct b43_phy
*phy
= &dev
->phy
;
842 struct b43_phy_g
*gphy
= phy
->g
;
845 u32
*stack
= gphy
->interfstack
;
848 case B43_INTERFMODE_NONWLAN
:
850 b43_phy_set(dev
, 0x042B, 0x0800);
851 b43_phy_mask(dev
, B43_PHY_G_CRS
, ~0x4000);
854 radio_stacksave(0x0078);
855 tmp
= (b43_radio_read16(dev
, 0x0078) & 0x001E);
856 B43_WARN_ON(tmp
> 15);
857 flipped
= bitrev4(tmp
);
858 if (flipped
< 10 && flipped
>= 8)
860 else if (flipped
>= 10)
862 flipped
= (bitrev4(flipped
) << 1) | 0x0020;
863 b43_radio_write16(dev
, 0x0078, flipped
);
865 b43_calc_nrssi_threshold(dev
);
867 phy_stacksave(0x0406);
868 b43_phy_write(dev
, 0x0406, 0x7E28);
870 b43_phy_set(dev
, 0x042B, 0x0800);
871 b43_phy_set(dev
, B43_PHY_RADIO_BITFIELD
, 0x1000);
873 phy_stacksave(0x04A0);
874 b43_phy_maskset(dev
, 0x04A0, 0xC0C0, 0x0008);
875 phy_stacksave(0x04A1);
876 b43_phy_maskset(dev
, 0x04A1, 0xC0C0, 0x0605);
877 phy_stacksave(0x04A2);
878 b43_phy_maskset(dev
, 0x04A2, 0xC0C0, 0x0204);
879 phy_stacksave(0x04A8);
880 b43_phy_maskset(dev
, 0x04A8, 0xC0C0, 0x0803);
881 phy_stacksave(0x04AB);
882 b43_phy_maskset(dev
, 0x04AB, 0xC0C0, 0x0605);
884 phy_stacksave(0x04A7);
885 b43_phy_write(dev
, 0x04A7, 0x0002);
886 phy_stacksave(0x04A3);
887 b43_phy_write(dev
, 0x04A3, 0x287A);
888 phy_stacksave(0x04A9);
889 b43_phy_write(dev
, 0x04A9, 0x2027);
890 phy_stacksave(0x0493);
891 b43_phy_write(dev
, 0x0493, 0x32F5);
892 phy_stacksave(0x04AA);
893 b43_phy_write(dev
, 0x04AA, 0x2027);
894 phy_stacksave(0x04AC);
895 b43_phy_write(dev
, 0x04AC, 0x32F5);
897 case B43_INTERFMODE_MANUALWLAN
:
898 if (b43_phy_read(dev
, 0x0033) & 0x0800)
901 gphy
->aci_enable
= true;
903 phy_stacksave(B43_PHY_RADIO_BITFIELD
);
904 phy_stacksave(B43_PHY_G_CRS
);
906 phy_stacksave(0x0406);
908 phy_stacksave(0x04C0);
909 phy_stacksave(0x04C1);
911 phy_stacksave(0x0033);
912 phy_stacksave(0x04A7);
913 phy_stacksave(0x04A3);
914 phy_stacksave(0x04A9);
915 phy_stacksave(0x04AA);
916 phy_stacksave(0x04AC);
917 phy_stacksave(0x0493);
918 phy_stacksave(0x04A1);
919 phy_stacksave(0x04A0);
920 phy_stacksave(0x04A2);
921 phy_stacksave(0x048A);
922 phy_stacksave(0x04A8);
923 phy_stacksave(0x04AB);
925 phy_stacksave(0x04AD);
926 phy_stacksave(0x04AE);
927 } else if (phy
->rev
>= 3) {
928 phy_stacksave(0x04AD);
929 phy_stacksave(0x0415);
930 phy_stacksave(0x0416);
931 phy_stacksave(0x0417);
932 ofdmtab_stacksave(0x1A00, 0x2);
933 ofdmtab_stacksave(0x1A00, 0x3);
935 phy_stacksave(0x042B);
936 phy_stacksave(0x048C);
938 b43_phy_mask(dev
, B43_PHY_RADIO_BITFIELD
, ~0x1000);
939 b43_phy_maskset(dev
, B43_PHY_G_CRS
, 0xFFFC, 0x0002);
941 b43_phy_write(dev
, 0x0033, 0x0800);
942 b43_phy_write(dev
, 0x04A3, 0x2027);
943 b43_phy_write(dev
, 0x04A9, 0x1CA8);
944 b43_phy_write(dev
, 0x0493, 0x287A);
945 b43_phy_write(dev
, 0x04AA, 0x1CA8);
946 b43_phy_write(dev
, 0x04AC, 0x287A);
948 b43_phy_maskset(dev
, 0x04A0, 0xFFC0, 0x001A);
949 b43_phy_write(dev
, 0x04A7, 0x000D);
952 b43_phy_write(dev
, 0x0406, 0xFF0D);
953 } else if (phy
->rev
== 2) {
954 b43_phy_write(dev
, 0x04C0, 0xFFFF);
955 b43_phy_write(dev
, 0x04C1, 0x00A9);
957 b43_phy_write(dev
, 0x04C0, 0x00C1);
958 b43_phy_write(dev
, 0x04C1, 0x0059);
961 b43_phy_maskset(dev
, 0x04A1, 0xC0FF, 0x1800);
962 b43_phy_maskset(dev
, 0x04A1, 0xFFC0, 0x0015);
963 b43_phy_maskset(dev
, 0x04A8, 0xCFFF, 0x1000);
964 b43_phy_maskset(dev
, 0x04A8, 0xF0FF, 0x0A00);
965 b43_phy_maskset(dev
, 0x04AB, 0xCFFF, 0x1000);
966 b43_phy_maskset(dev
, 0x04AB, 0xF0FF, 0x0800);
967 b43_phy_maskset(dev
, 0x04AB, 0xFFCF, 0x0010);
968 b43_phy_maskset(dev
, 0x04AB, 0xFFF0, 0x0005);
969 b43_phy_maskset(dev
, 0x04A8, 0xFFCF, 0x0010);
970 b43_phy_maskset(dev
, 0x04A8, 0xFFF0, 0x0006);
971 b43_phy_maskset(dev
, 0x04A2, 0xF0FF, 0x0800);
972 b43_phy_maskset(dev
, 0x04A0, 0xF0FF, 0x0500);
973 b43_phy_maskset(dev
, 0x04A2, 0xFFF0, 0x000B);
976 b43_phy_mask(dev
, 0x048A, 0x7FFF);
977 b43_phy_maskset(dev
, 0x0415, 0x8000, 0x36D8);
978 b43_phy_maskset(dev
, 0x0416, 0x8000, 0x36D8);
979 b43_phy_maskset(dev
, 0x0417, 0xFE00, 0x016D);
981 b43_phy_set(dev
, 0x048A, 0x1000);
982 b43_phy_maskset(dev
, 0x048A, 0x9FFF, 0x2000);
983 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_ACIW
);
986 b43_phy_set(dev
, 0x042B, 0x0800);
988 b43_phy_maskset(dev
, 0x048C, 0xF0FF, 0x0200);
990 b43_phy_maskset(dev
, 0x04AE, 0xFF00, 0x007F);
991 b43_phy_maskset(dev
, 0x04AD, 0x00FF, 0x1300);
992 } else if (phy
->rev
>= 6) {
993 b43_ofdmtab_write16(dev
, 0x1A00, 0x3, 0x007F);
994 b43_ofdmtab_write16(dev
, 0x1A00, 0x2, 0x007F);
995 b43_phy_mask(dev
, 0x04AD, 0x00FF);
997 b43_calc_nrssi_slope(dev
);
1005 b43_radio_interference_mitigation_disable(struct b43_wldev
*dev
, int mode
)
1007 struct b43_phy
*phy
= &dev
->phy
;
1008 struct b43_phy_g
*gphy
= phy
->g
;
1009 u32
*stack
= gphy
->interfstack
;
1012 case B43_INTERFMODE_NONWLAN
:
1013 if (phy
->rev
!= 1) {
1014 b43_phy_mask(dev
, 0x042B, ~0x0800);
1015 b43_phy_set(dev
, B43_PHY_G_CRS
, 0x4000);
1018 radio_stackrestore(0x0078);
1019 b43_calc_nrssi_threshold(dev
);
1020 phy_stackrestore(0x0406);
1021 b43_phy_mask(dev
, 0x042B, ~0x0800);
1022 if (!dev
->bad_frames_preempt
) {
1023 b43_phy_mask(dev
, B43_PHY_RADIO_BITFIELD
, ~(1 << 11));
1025 b43_phy_set(dev
, B43_PHY_G_CRS
, 0x4000);
1026 phy_stackrestore(0x04A0);
1027 phy_stackrestore(0x04A1);
1028 phy_stackrestore(0x04A2);
1029 phy_stackrestore(0x04A8);
1030 phy_stackrestore(0x04AB);
1031 phy_stackrestore(0x04A7);
1032 phy_stackrestore(0x04A3);
1033 phy_stackrestore(0x04A9);
1034 phy_stackrestore(0x0493);
1035 phy_stackrestore(0x04AA);
1036 phy_stackrestore(0x04AC);
1038 case B43_INTERFMODE_MANUALWLAN
:
1039 if (!(b43_phy_read(dev
, 0x0033) & 0x0800))
1042 gphy
->aci_enable
= false;
1044 phy_stackrestore(B43_PHY_RADIO_BITFIELD
);
1045 phy_stackrestore(B43_PHY_G_CRS
);
1046 phy_stackrestore(0x0033);
1047 phy_stackrestore(0x04A3);
1048 phy_stackrestore(0x04A9);
1049 phy_stackrestore(0x0493);
1050 phy_stackrestore(0x04AA);
1051 phy_stackrestore(0x04AC);
1052 phy_stackrestore(0x04A0);
1053 phy_stackrestore(0x04A7);
1054 if (phy
->rev
>= 2) {
1055 phy_stackrestore(0x04C0);
1056 phy_stackrestore(0x04C1);
1058 phy_stackrestore(0x0406);
1059 phy_stackrestore(0x04A1);
1060 phy_stackrestore(0x04AB);
1061 phy_stackrestore(0x04A8);
1062 if (phy
->rev
== 2) {
1063 phy_stackrestore(0x04AD);
1064 phy_stackrestore(0x04AE);
1065 } else if (phy
->rev
>= 3) {
1066 phy_stackrestore(0x04AD);
1067 phy_stackrestore(0x0415);
1068 phy_stackrestore(0x0416);
1069 phy_stackrestore(0x0417);
1070 ofdmtab_stackrestore(0x1A00, 0x2);
1071 ofdmtab_stackrestore(0x1A00, 0x3);
1073 phy_stackrestore(0x04A2);
1074 phy_stackrestore(0x048A);
1075 phy_stackrestore(0x042B);
1076 phy_stackrestore(0x048C);
1077 b43_hf_write(dev
, b43_hf_read(dev
) & ~B43_HF_ACIW
);
1078 b43_calc_nrssi_slope(dev
);
1085 #undef phy_stacksave
1086 #undef phy_stackrestore
1087 #undef radio_stacksave
1088 #undef radio_stackrestore
1089 #undef ofdmtab_stacksave
1090 #undef ofdmtab_stackrestore
1092 static u16
b43_radio_core_calibration_value(struct b43_wldev
*dev
)
1094 u16 reg
, index
, ret
;
1096 static const u8 rcc_table
[] = {
1097 0x02, 0x03, 0x01, 0x0F,
1098 0x06, 0x07, 0x05, 0x0F,
1099 0x0A, 0x0B, 0x09, 0x0F,
1100 0x0E, 0x0F, 0x0D, 0x0F,
1103 reg
= b43_radio_read16(dev
, 0x60);
1104 index
= (reg
& 0x001E) >> 1;
1105 ret
= rcc_table
[index
] << 1;
1106 ret
|= (reg
& 0x0001);
1112 #define LPD(L, P, D) (((L) << 2) | ((P) << 1) | ((D) << 0))
1113 static u16
radio2050_rfover_val(struct b43_wldev
*dev
,
1114 u16 phy_register
, unsigned int lpd
)
1116 struct b43_phy
*phy
= &dev
->phy
;
1117 struct b43_phy_g
*gphy
= phy
->g
;
1118 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
1123 if (has_loopback_gain(phy
)) {
1124 int max_lb_gain
= gphy
->max_lb_gain
;
1128 if (phy
->radio_rev
== 8)
1129 max_lb_gain
+= 0x3E;
1131 max_lb_gain
+= 0x26;
1132 if (max_lb_gain
>= 0x46) {
1134 max_lb_gain
-= 0x46;
1135 } else if (max_lb_gain
>= 0x3A) {
1137 max_lb_gain
-= 0x3A;
1138 } else if (max_lb_gain
>= 0x2E) {
1140 max_lb_gain
-= 0x2E;
1143 max_lb_gain
-= 0x10;
1146 for (i
= 0; i
< 16; i
++) {
1147 max_lb_gain
-= (i
* 6);
1148 if (max_lb_gain
< 6)
1152 if ((phy
->rev
< 7) ||
1153 !(sprom
->boardflags_lo
& B43_BFL_EXTLNA
)) {
1154 if (phy_register
== B43_PHY_RFOVER
) {
1156 } else if (phy_register
== B43_PHY_RFOVERVAL
) {
1163 return (0x0092 | extlna
);
1165 return (0x0093 | extlna
);
1171 if (phy_register
== B43_PHY_RFOVER
) {
1173 } else if (phy_register
== B43_PHY_RFOVERVAL
) {
1181 return (0x8092 | extlna
);
1183 return (0x2092 | extlna
);
1185 return (0x2093 | extlna
);
1192 if ((phy
->rev
< 7) ||
1193 !(sprom
->boardflags_lo
& B43_BFL_EXTLNA
)) {
1194 if (phy_register
== B43_PHY_RFOVER
) {
1196 } else if (phy_register
== B43_PHY_RFOVERVAL
) {
1211 if (phy_register
== B43_PHY_RFOVER
) {
1213 } else if (phy_register
== B43_PHY_RFOVERVAL
) {
1232 struct init2050_saved_values
{
1233 /* Core registers */
1237 /* Radio registers */
1250 u16 phy_analogoverval
;
1258 static u16
b43_radio_init2050(struct b43_wldev
*dev
)
1260 struct b43_phy
*phy
= &dev
->phy
;
1261 struct init2050_saved_values sav
;
1266 u32 tmp1
= 0, tmp2
= 0;
1268 memset(&sav
, 0, sizeof(sav
)); /* get rid of "may be used uninitialized..." */
1270 sav
.radio_43
= b43_radio_read16(dev
, 0x43);
1271 sav
.radio_51
= b43_radio_read16(dev
, 0x51);
1272 sav
.radio_52
= b43_radio_read16(dev
, 0x52);
1273 sav
.phy_pgactl
= b43_phy_read(dev
, B43_PHY_PGACTL
);
1274 sav
.phy_cck_5A
= b43_phy_read(dev
, B43_PHY_CCK(0x5A));
1275 sav
.phy_cck_59
= b43_phy_read(dev
, B43_PHY_CCK(0x59));
1276 sav
.phy_cck_58
= b43_phy_read(dev
, B43_PHY_CCK(0x58));
1278 if (phy
->type
== B43_PHYTYPE_B
) {
1279 sav
.phy_cck_30
= b43_phy_read(dev
, B43_PHY_CCK(0x30));
1280 sav
.reg_3EC
= b43_read16(dev
, 0x3EC);
1282 b43_phy_write(dev
, B43_PHY_CCK(0x30), 0xFF);
1283 b43_write16(dev
, 0x3EC, 0x3F3F);
1284 } else if (phy
->gmode
|| phy
->rev
>= 2) {
1285 sav
.phy_rfover
= b43_phy_read(dev
, B43_PHY_RFOVER
);
1286 sav
.phy_rfoverval
= b43_phy_read(dev
, B43_PHY_RFOVERVAL
);
1287 sav
.phy_analogover
= b43_phy_read(dev
, B43_PHY_ANALOGOVER
);
1288 sav
.phy_analogoverval
=
1289 b43_phy_read(dev
, B43_PHY_ANALOGOVERVAL
);
1290 sav
.phy_crs0
= b43_phy_read(dev
, B43_PHY_CRS0
);
1291 sav
.phy_classctl
= b43_phy_read(dev
, B43_PHY_CLASSCTL
);
1293 b43_phy_set(dev
, B43_PHY_ANALOGOVER
, 0x0003);
1294 b43_phy_mask(dev
, B43_PHY_ANALOGOVERVAL
, 0xFFFC);
1295 b43_phy_mask(dev
, B43_PHY_CRS0
, 0x7FFF);
1296 b43_phy_mask(dev
, B43_PHY_CLASSCTL
, 0xFFFC);
1297 if (has_loopback_gain(phy
)) {
1298 sav
.phy_lo_mask
= b43_phy_read(dev
, B43_PHY_LO_MASK
);
1299 sav
.phy_lo_ctl
= b43_phy_read(dev
, B43_PHY_LO_CTL
);
1302 b43_phy_write(dev
, B43_PHY_LO_MASK
, 0xC020);
1304 b43_phy_write(dev
, B43_PHY_LO_MASK
, 0x8020);
1305 b43_phy_write(dev
, B43_PHY_LO_CTL
, 0);
1308 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1309 radio2050_rfover_val(dev
, B43_PHY_RFOVERVAL
,
1311 b43_phy_write(dev
, B43_PHY_RFOVER
,
1312 radio2050_rfover_val(dev
, B43_PHY_RFOVER
, 0));
1314 b43_write16(dev
, 0x3E2, b43_read16(dev
, 0x3E2) | 0x8000);
1316 sav
.phy_syncctl
= b43_phy_read(dev
, B43_PHY_SYNCCTL
);
1317 b43_phy_mask(dev
, B43_PHY_SYNCCTL
, 0xFF7F);
1318 sav
.reg_3E6
= b43_read16(dev
, 0x3E6);
1319 sav
.reg_3F4
= b43_read16(dev
, 0x3F4);
1321 if (phy
->analog
== 0) {
1322 b43_write16(dev
, 0x03E6, 0x0122);
1324 if (phy
->analog
>= 2) {
1325 b43_phy_maskset(dev
, B43_PHY_CCK(0x03), 0xFFBF, 0x40);
1327 b43_write16(dev
, B43_MMIO_CHANNEL_EXT
,
1328 (b43_read16(dev
, B43_MMIO_CHANNEL_EXT
) | 0x2000));
1331 rcc
= b43_radio_core_calibration_value(dev
);
1333 if (phy
->type
== B43_PHYTYPE_B
)
1334 b43_radio_write16(dev
, 0x78, 0x26);
1335 if (phy
->gmode
|| phy
->rev
>= 2) {
1336 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1337 radio2050_rfover_val(dev
, B43_PHY_RFOVERVAL
,
1340 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xBFAF);
1341 b43_phy_write(dev
, B43_PHY_CCK(0x2B), 0x1403);
1342 if (phy
->gmode
|| phy
->rev
>= 2) {
1343 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1344 radio2050_rfover_val(dev
, B43_PHY_RFOVERVAL
,
1347 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xBFA0);
1348 b43_radio_set(dev
, 0x51, 0x0004);
1349 if (phy
->radio_rev
== 8) {
1350 b43_radio_write16(dev
, 0x43, 0x1F);
1352 b43_radio_write16(dev
, 0x52, 0);
1353 b43_radio_maskset(dev
, 0x43, 0xFFF0, 0x0009);
1355 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0);
1357 for (i
= 0; i
< 16; i
++) {
1358 b43_phy_write(dev
, B43_PHY_CCK(0x5A), 0x0480);
1359 b43_phy_write(dev
, B43_PHY_CCK(0x59), 0xC810);
1360 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0x000D);
1361 if (phy
->gmode
|| phy
->rev
>= 2) {
1362 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1363 radio2050_rfover_val(dev
,
1367 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xAFB0);
1369 if (phy
->gmode
|| phy
->rev
>= 2) {
1370 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1371 radio2050_rfover_val(dev
,
1375 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xEFB0);
1377 if (phy
->gmode
|| phy
->rev
>= 2) {
1378 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1379 radio2050_rfover_val(dev
,
1383 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xFFF0);
1385 tmp1
+= b43_phy_read(dev
, B43_PHY_LO_LEAKAGE
);
1386 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0);
1387 if (phy
->gmode
|| phy
->rev
>= 2) {
1388 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1389 radio2050_rfover_val(dev
,
1393 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xAFB0);
1397 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0);
1401 for (i
= 0; i
< 16; i
++) {
1402 radio78
= (bitrev4(i
) << 1) | 0x0020;
1403 b43_radio_write16(dev
, 0x78, radio78
);
1405 for (j
= 0; j
< 16; j
++) {
1406 b43_phy_write(dev
, B43_PHY_CCK(0x5A), 0x0D80);
1407 b43_phy_write(dev
, B43_PHY_CCK(0x59), 0xC810);
1408 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0x000D);
1409 if (phy
->gmode
|| phy
->rev
>= 2) {
1410 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1411 radio2050_rfover_val(dev
,
1416 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xAFB0);
1418 if (phy
->gmode
|| phy
->rev
>= 2) {
1419 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1420 radio2050_rfover_val(dev
,
1425 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xEFB0);
1427 if (phy
->gmode
|| phy
->rev
>= 2) {
1428 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1429 radio2050_rfover_val(dev
,
1434 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xFFF0);
1436 tmp2
+= b43_phy_read(dev
, B43_PHY_LO_LEAKAGE
);
1437 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0);
1438 if (phy
->gmode
|| phy
->rev
>= 2) {
1439 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
1440 radio2050_rfover_val(dev
,
1445 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xAFB0);
1453 /* Restore the registers */
1454 b43_phy_write(dev
, B43_PHY_PGACTL
, sav
.phy_pgactl
);
1455 b43_radio_write16(dev
, 0x51, sav
.radio_51
);
1456 b43_radio_write16(dev
, 0x52, sav
.radio_52
);
1457 b43_radio_write16(dev
, 0x43, sav
.radio_43
);
1458 b43_phy_write(dev
, B43_PHY_CCK(0x5A), sav
.phy_cck_5A
);
1459 b43_phy_write(dev
, B43_PHY_CCK(0x59), sav
.phy_cck_59
);
1460 b43_phy_write(dev
, B43_PHY_CCK(0x58), sav
.phy_cck_58
);
1461 b43_write16(dev
, 0x3E6, sav
.reg_3E6
);
1462 if (phy
->analog
!= 0)
1463 b43_write16(dev
, 0x3F4, sav
.reg_3F4
);
1464 b43_phy_write(dev
, B43_PHY_SYNCCTL
, sav
.phy_syncctl
);
1465 b43_synth_pu_workaround(dev
, phy
->channel
);
1466 if (phy
->type
== B43_PHYTYPE_B
) {
1467 b43_phy_write(dev
, B43_PHY_CCK(0x30), sav
.phy_cck_30
);
1468 b43_write16(dev
, 0x3EC, sav
.reg_3EC
);
1469 } else if (phy
->gmode
) {
1470 b43_write16(dev
, B43_MMIO_PHY_RADIO
,
1471 b43_read16(dev
, B43_MMIO_PHY_RADIO
)
1473 b43_phy_write(dev
, B43_PHY_RFOVER
, sav
.phy_rfover
);
1474 b43_phy_write(dev
, B43_PHY_RFOVERVAL
, sav
.phy_rfoverval
);
1475 b43_phy_write(dev
, B43_PHY_ANALOGOVER
, sav
.phy_analogover
);
1476 b43_phy_write(dev
, B43_PHY_ANALOGOVERVAL
,
1477 sav
.phy_analogoverval
);
1478 b43_phy_write(dev
, B43_PHY_CRS0
, sav
.phy_crs0
);
1479 b43_phy_write(dev
, B43_PHY_CLASSCTL
, sav
.phy_classctl
);
1480 if (has_loopback_gain(phy
)) {
1481 b43_phy_write(dev
, B43_PHY_LO_MASK
, sav
.phy_lo_mask
);
1482 b43_phy_write(dev
, B43_PHY_LO_CTL
, sav
.phy_lo_ctl
);
1493 static void b43_phy_initb5(struct b43_wldev
*dev
)
1495 struct b43_phy
*phy
= &dev
->phy
;
1496 struct b43_phy_g
*gphy
= phy
->g
;
1500 if (phy
->analog
== 1) {
1501 b43_radio_set(dev
, 0x007A, 0x0050);
1503 if ((dev
->dev
->board_vendor
!= SSB_BOARDVENDOR_BCM
) &&
1504 (dev
->dev
->board_type
!= SSB_BOARD_BU4306
)) {
1506 for (offset
= 0x00A8; offset
< 0x00C7; offset
++) {
1507 b43_phy_write(dev
, offset
, value
);
1511 b43_phy_maskset(dev
, 0x0035, 0xF0FF, 0x0700);
1512 if (phy
->radio_ver
== 0x2050)
1513 b43_phy_write(dev
, 0x0038, 0x0667);
1515 if (phy
->gmode
|| phy
->rev
>= 2) {
1516 if (phy
->radio_ver
== 0x2050) {
1517 b43_radio_set(dev
, 0x007A, 0x0020);
1518 b43_radio_set(dev
, 0x0051, 0x0004);
1520 b43_write16(dev
, B43_MMIO_PHY_RADIO
, 0x0000);
1522 b43_phy_set(dev
, 0x0802, 0x0100);
1523 b43_phy_set(dev
, 0x042B, 0x2000);
1525 b43_phy_write(dev
, 0x001C, 0x186A);
1527 b43_phy_maskset(dev
, 0x0013, 0x00FF, 0x1900);
1528 b43_phy_maskset(dev
, 0x0035, 0xFFC0, 0x0064);
1529 b43_phy_maskset(dev
, 0x005D, 0xFF80, 0x000A);
1532 if (dev
->bad_frames_preempt
) {
1533 b43_phy_set(dev
, B43_PHY_RADIO_BITFIELD
, (1 << 11));
1536 if (phy
->analog
== 1) {
1537 b43_phy_write(dev
, 0x0026, 0xCE00);
1538 b43_phy_write(dev
, 0x0021, 0x3763);
1539 b43_phy_write(dev
, 0x0022, 0x1BC3);
1540 b43_phy_write(dev
, 0x0023, 0x06F9);
1541 b43_phy_write(dev
, 0x0024, 0x037E);
1543 b43_phy_write(dev
, 0x0026, 0xCC00);
1544 b43_phy_write(dev
, 0x0030, 0x00C6);
1545 b43_write16(dev
, 0x03EC, 0x3F22);
1547 if (phy
->analog
== 1)
1548 b43_phy_write(dev
, 0x0020, 0x3E1C);
1550 b43_phy_write(dev
, 0x0020, 0x301C);
1552 if (phy
->analog
== 0)
1553 b43_write16(dev
, 0x03E4, 0x3000);
1555 old_channel
= phy
->channel
;
1556 /* Force to channel 7, even if not supported. */
1557 b43_gphy_channel_switch(dev
, 7, 0);
1559 if (phy
->radio_ver
!= 0x2050) {
1560 b43_radio_write16(dev
, 0x0075, 0x0080);
1561 b43_radio_write16(dev
, 0x0079, 0x0081);
1564 b43_radio_write16(dev
, 0x0050, 0x0020);
1565 b43_radio_write16(dev
, 0x0050, 0x0023);
1567 if (phy
->radio_ver
== 0x2050) {
1568 b43_radio_write16(dev
, 0x0050, 0x0020);
1569 b43_radio_write16(dev
, 0x005A, 0x0070);
1572 b43_radio_write16(dev
, 0x005B, 0x007B);
1573 b43_radio_write16(dev
, 0x005C, 0x00B0);
1575 b43_radio_set(dev
, 0x007A, 0x0007);
1577 b43_gphy_channel_switch(dev
, old_channel
, 0);
1579 b43_phy_write(dev
, 0x0014, 0x0080);
1580 b43_phy_write(dev
, 0x0032, 0x00CA);
1581 b43_phy_write(dev
, 0x002A, 0x88A3);
1583 b43_set_txpower_g(dev
, &gphy
->bbatt
, &gphy
->rfatt
, gphy
->tx_control
);
1585 if (phy
->radio_ver
== 0x2050)
1586 b43_radio_write16(dev
, 0x005D, 0x000D);
1588 b43_write16(dev
, 0x03E4, (b43_read16(dev
, 0x03E4) & 0xFFC0) | 0x0004);
1591 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Init/B6 */
1592 static void b43_phy_initb6(struct b43_wldev
*dev
)
1594 struct b43_phy
*phy
= &dev
->phy
;
1595 struct b43_phy_g
*gphy
= phy
->g
;
1599 b43_phy_write(dev
, 0x003E, 0x817A);
1600 b43_radio_write16(dev
, 0x007A,
1601 (b43_radio_read16(dev
, 0x007A) | 0x0058));
1602 if (phy
->radio_rev
== 4 || phy
->radio_rev
== 5) {
1603 b43_radio_write16(dev
, 0x51, 0x37);
1604 b43_radio_write16(dev
, 0x52, 0x70);
1605 b43_radio_write16(dev
, 0x53, 0xB3);
1606 b43_radio_write16(dev
, 0x54, 0x9B);
1607 b43_radio_write16(dev
, 0x5A, 0x88);
1608 b43_radio_write16(dev
, 0x5B, 0x88);
1609 b43_radio_write16(dev
, 0x5D, 0x88);
1610 b43_radio_write16(dev
, 0x5E, 0x88);
1611 b43_radio_write16(dev
, 0x7D, 0x88);
1612 b43_hf_write(dev
, b43_hf_read(dev
)
1613 | B43_HF_TSSIRPSMW
);
1615 B43_WARN_ON(phy
->radio_rev
== 6 || phy
->radio_rev
== 7); /* We had code for these revs here... */
1616 if (phy
->radio_rev
== 8) {
1617 b43_radio_write16(dev
, 0x51, 0);
1618 b43_radio_write16(dev
, 0x52, 0x40);
1619 b43_radio_write16(dev
, 0x53, 0xB7);
1620 b43_radio_write16(dev
, 0x54, 0x98);
1621 b43_radio_write16(dev
, 0x5A, 0x88);
1622 b43_radio_write16(dev
, 0x5B, 0x6B);
1623 b43_radio_write16(dev
, 0x5C, 0x0F);
1624 if (dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_ALTIQ
) {
1625 b43_radio_write16(dev
, 0x5D, 0xFA);
1626 b43_radio_write16(dev
, 0x5E, 0xD8);
1628 b43_radio_write16(dev
, 0x5D, 0xF5);
1629 b43_radio_write16(dev
, 0x5E, 0xB8);
1631 b43_radio_write16(dev
, 0x0073, 0x0003);
1632 b43_radio_write16(dev
, 0x007D, 0x00A8);
1633 b43_radio_write16(dev
, 0x007C, 0x0001);
1634 b43_radio_write16(dev
, 0x007E, 0x0008);
1637 for (offset
= 0x0088; offset
< 0x0098; offset
++) {
1638 b43_phy_write(dev
, offset
, val
);
1642 for (offset
= 0x0098; offset
< 0x00A8; offset
++) {
1643 b43_phy_write(dev
, offset
, val
);
1647 for (offset
= 0x00A8; offset
< 0x00C8; offset
++) {
1648 b43_phy_write(dev
, offset
, (val
& 0x3F3F));
1651 if (phy
->type
== B43_PHYTYPE_G
) {
1652 b43_radio_set(dev
, 0x007A, 0x0020);
1653 b43_radio_set(dev
, 0x0051, 0x0004);
1654 b43_phy_set(dev
, 0x0802, 0x0100);
1655 b43_phy_set(dev
, 0x042B, 0x2000);
1656 b43_phy_write(dev
, 0x5B, 0);
1657 b43_phy_write(dev
, 0x5C, 0);
1660 old_channel
= phy
->channel
;
1661 if (old_channel
>= 8)
1662 b43_gphy_channel_switch(dev
, 1, 0);
1664 b43_gphy_channel_switch(dev
, 13, 0);
1666 b43_radio_write16(dev
, 0x0050, 0x0020);
1667 b43_radio_write16(dev
, 0x0050, 0x0023);
1669 if (phy
->radio_rev
< 6 || phy
->radio_rev
== 8) {
1670 b43_radio_write16(dev
, 0x7C, (b43_radio_read16(dev
, 0x7C)
1672 b43_radio_write16(dev
, 0x50, 0x20);
1674 if (phy
->radio_rev
<= 2) {
1675 b43_radio_write16(dev
, 0x50, 0x20);
1676 b43_radio_write16(dev
, 0x5A, 0x70);
1677 b43_radio_write16(dev
, 0x5B, 0x7B);
1678 b43_radio_write16(dev
, 0x5C, 0xB0);
1680 b43_radio_maskset(dev
, 0x007A, 0x00F8, 0x0007);
1682 b43_gphy_channel_switch(dev
, old_channel
, 0);
1684 b43_phy_write(dev
, 0x0014, 0x0200);
1685 if (phy
->radio_rev
>= 6)
1686 b43_phy_write(dev
, 0x2A, 0x88C2);
1688 b43_phy_write(dev
, 0x2A, 0x8AC0);
1689 b43_phy_write(dev
, 0x0038, 0x0668);
1690 b43_set_txpower_g(dev
, &gphy
->bbatt
, &gphy
->rfatt
, gphy
->tx_control
);
1691 if (phy
->radio_rev
== 4 || phy
->radio_rev
== 5)
1692 b43_phy_maskset(dev
, 0x5D, 0xFF80, 0x0003);
1693 if (phy
->radio_rev
<= 2)
1694 b43_radio_write16(dev
, 0x005D, 0x000D);
1696 if (phy
->analog
== 4) {
1697 b43_write16(dev
, 0x3E4, 9);
1698 b43_phy_mask(dev
, 0x61, 0x0FFF);
1700 b43_phy_maskset(dev
, 0x0002, 0xFFC0, 0x0004);
1702 if (phy
->type
== B43_PHYTYPE_B
)
1704 else if (phy
->type
== B43_PHYTYPE_G
)
1705 b43_write16(dev
, 0x03E6, 0x0);
1708 static void b43_calc_loopback_gain(struct b43_wldev
*dev
)
1710 struct b43_phy
*phy
= &dev
->phy
;
1711 struct b43_phy_g
*gphy
= phy
->g
;
1712 u16 backup_phy
[16] = { 0 };
1713 u16 backup_radio
[3];
1715 u16 i
, j
, loop_i_max
;
1717 u16 loop1_outer_done
, loop1_inner_done
;
1719 backup_phy
[0] = b43_phy_read(dev
, B43_PHY_CRS0
);
1720 backup_phy
[1] = b43_phy_read(dev
, B43_PHY_CCKBBANDCFG
);
1721 backup_phy
[2] = b43_phy_read(dev
, B43_PHY_RFOVER
);
1722 backup_phy
[3] = b43_phy_read(dev
, B43_PHY_RFOVERVAL
);
1723 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
1724 backup_phy
[4] = b43_phy_read(dev
, B43_PHY_ANALOGOVER
);
1725 backup_phy
[5] = b43_phy_read(dev
, B43_PHY_ANALOGOVERVAL
);
1727 backup_phy
[6] = b43_phy_read(dev
, B43_PHY_CCK(0x5A));
1728 backup_phy
[7] = b43_phy_read(dev
, B43_PHY_CCK(0x59));
1729 backup_phy
[8] = b43_phy_read(dev
, B43_PHY_CCK(0x58));
1730 backup_phy
[9] = b43_phy_read(dev
, B43_PHY_CCK(0x0A));
1731 backup_phy
[10] = b43_phy_read(dev
, B43_PHY_CCK(0x03));
1732 backup_phy
[11] = b43_phy_read(dev
, B43_PHY_LO_MASK
);
1733 backup_phy
[12] = b43_phy_read(dev
, B43_PHY_LO_CTL
);
1734 backup_phy
[13] = b43_phy_read(dev
, B43_PHY_CCK(0x2B));
1735 backup_phy
[14] = b43_phy_read(dev
, B43_PHY_PGACTL
);
1736 backup_phy
[15] = b43_phy_read(dev
, B43_PHY_LO_LEAKAGE
);
1737 backup_bband
= gphy
->bbatt
.att
;
1738 backup_radio
[0] = b43_radio_read16(dev
, 0x52);
1739 backup_radio
[1] = b43_radio_read16(dev
, 0x43);
1740 backup_radio
[2] = b43_radio_read16(dev
, 0x7A);
1742 b43_phy_mask(dev
, B43_PHY_CRS0
, 0x3FFF);
1743 b43_phy_set(dev
, B43_PHY_CCKBBANDCFG
, 0x8000);
1744 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x0002);
1745 b43_phy_mask(dev
, B43_PHY_RFOVERVAL
, 0xFFFD);
1746 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x0001);
1747 b43_phy_mask(dev
, B43_PHY_RFOVERVAL
, 0xFFFE);
1748 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
1749 b43_phy_set(dev
, B43_PHY_ANALOGOVER
, 0x0001);
1750 b43_phy_mask(dev
, B43_PHY_ANALOGOVERVAL
, 0xFFFE);
1751 b43_phy_set(dev
, B43_PHY_ANALOGOVER
, 0x0002);
1752 b43_phy_mask(dev
, B43_PHY_ANALOGOVERVAL
, 0xFFFD);
1754 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x000C);
1755 b43_phy_set(dev
, B43_PHY_RFOVERVAL
, 0x000C);
1756 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x0030);
1757 b43_phy_maskset(dev
, B43_PHY_RFOVERVAL
, 0xFFCF, 0x10);
1759 b43_phy_write(dev
, B43_PHY_CCK(0x5A), 0x0780);
1760 b43_phy_write(dev
, B43_PHY_CCK(0x59), 0xC810);
1761 b43_phy_write(dev
, B43_PHY_CCK(0x58), 0x000D);
1763 b43_phy_set(dev
, B43_PHY_CCK(0x0A), 0x2000);
1764 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
1765 b43_phy_set(dev
, B43_PHY_ANALOGOVER
, 0x0004);
1766 b43_phy_mask(dev
, B43_PHY_ANALOGOVERVAL
, 0xFFFB);
1768 b43_phy_maskset(dev
, B43_PHY_CCK(0x03), 0xFF9F, 0x40);
1770 if (phy
->radio_rev
== 8) {
1771 b43_radio_write16(dev
, 0x43, 0x000F);
1773 b43_radio_write16(dev
, 0x52, 0);
1774 b43_radio_maskset(dev
, 0x43, 0xFFF0, 0x9);
1776 b43_gphy_set_baseband_attenuation(dev
, 11);
1779 b43_phy_write(dev
, B43_PHY_LO_MASK
, 0xC020);
1781 b43_phy_write(dev
, B43_PHY_LO_MASK
, 0x8020);
1782 b43_phy_write(dev
, B43_PHY_LO_CTL
, 0);
1784 b43_phy_maskset(dev
, B43_PHY_CCK(0x2B), 0xFFC0, 0x01);
1785 b43_phy_maskset(dev
, B43_PHY_CCK(0x2B), 0xC0FF, 0x800);
1787 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x0100);
1788 b43_phy_mask(dev
, B43_PHY_RFOVERVAL
, 0xCFFF);
1790 if (dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_EXTLNA
) {
1791 if (phy
->rev
>= 7) {
1792 b43_phy_set(dev
, B43_PHY_RFOVER
, 0x0800);
1793 b43_phy_set(dev
, B43_PHY_RFOVERVAL
, 0x8000);
1796 b43_radio_mask(dev
, 0x7A, 0x00F7);
1799 loop_i_max
= (phy
->radio_rev
== 8) ? 15 : 9;
1800 for (i
= 0; i
< loop_i_max
; i
++) {
1801 for (j
= 0; j
< 16; j
++) {
1802 b43_radio_write16(dev
, 0x43, i
);
1803 b43_phy_maskset(dev
, B43_PHY_RFOVERVAL
, 0xF0FF, (j
<< 8));
1804 b43_phy_maskset(dev
, B43_PHY_PGACTL
, 0x0FFF, 0xA000);
1805 b43_phy_set(dev
, B43_PHY_PGACTL
, 0xF000);
1807 if (b43_phy_read(dev
, B43_PHY_LO_LEAKAGE
) >= 0xDFC)
1812 loop1_outer_done
= i
;
1813 loop1_inner_done
= j
;
1815 b43_phy_set(dev
, B43_PHY_RFOVERVAL
, 0x30);
1817 for (j
= j
- 8; j
< 16; j
++) {
1818 b43_phy_maskset(dev
, B43_PHY_RFOVERVAL
, 0xF0FF, (j
<< 8));
1819 b43_phy_maskset(dev
, B43_PHY_PGACTL
, 0x0FFF, 0xA000);
1820 b43_phy_set(dev
, B43_PHY_PGACTL
, 0xF000);
1823 if (b43_phy_read(dev
, B43_PHY_LO_LEAKAGE
) >= 0xDFC)
1830 if (phy
->rev
!= 1) { /* Not in specs, but needed to prevent PPC machine check */
1831 b43_phy_write(dev
, B43_PHY_ANALOGOVER
, backup_phy
[4]);
1832 b43_phy_write(dev
, B43_PHY_ANALOGOVERVAL
, backup_phy
[5]);
1834 b43_phy_write(dev
, B43_PHY_CCK(0x5A), backup_phy
[6]);
1835 b43_phy_write(dev
, B43_PHY_CCK(0x59), backup_phy
[7]);
1836 b43_phy_write(dev
, B43_PHY_CCK(0x58), backup_phy
[8]);
1837 b43_phy_write(dev
, B43_PHY_CCK(0x0A), backup_phy
[9]);
1838 b43_phy_write(dev
, B43_PHY_CCK(0x03), backup_phy
[10]);
1839 b43_phy_write(dev
, B43_PHY_LO_MASK
, backup_phy
[11]);
1840 b43_phy_write(dev
, B43_PHY_LO_CTL
, backup_phy
[12]);
1841 b43_phy_write(dev
, B43_PHY_CCK(0x2B), backup_phy
[13]);
1842 b43_phy_write(dev
, B43_PHY_PGACTL
, backup_phy
[14]);
1844 b43_gphy_set_baseband_attenuation(dev
, backup_bband
);
1846 b43_radio_write16(dev
, 0x52, backup_radio
[0]);
1847 b43_radio_write16(dev
, 0x43, backup_radio
[1]);
1848 b43_radio_write16(dev
, 0x7A, backup_radio
[2]);
1850 b43_phy_write(dev
, B43_PHY_RFOVER
, backup_phy
[2] | 0x0003);
1852 b43_phy_write(dev
, B43_PHY_RFOVER
, backup_phy
[2]);
1853 b43_phy_write(dev
, B43_PHY_RFOVERVAL
, backup_phy
[3]);
1854 b43_phy_write(dev
, B43_PHY_CRS0
, backup_phy
[0]);
1855 b43_phy_write(dev
, B43_PHY_CCKBBANDCFG
, backup_phy
[1]);
1858 ((loop1_inner_done
* 6) - (loop1_outer_done
* 4)) - 11;
1859 gphy
->trsw_rx_gain
= trsw_rx
* 2;
1862 static void b43_hardware_pctl_early_init(struct b43_wldev
*dev
)
1864 struct b43_phy
*phy
= &dev
->phy
;
1866 if (!b43_has_hardware_pctl(dev
)) {
1867 b43_phy_write(dev
, 0x047A, 0xC111);
1871 b43_phy_mask(dev
, 0x0036, 0xFEFF);
1872 b43_phy_write(dev
, 0x002F, 0x0202);
1873 b43_phy_set(dev
, 0x047C, 0x0002);
1874 b43_phy_set(dev
, 0x047A, 0xF000);
1875 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
== 8) {
1876 b43_phy_maskset(dev
, 0x047A, 0xFF0F, 0x0010);
1877 b43_phy_set(dev
, 0x005D, 0x8000);
1878 b43_phy_maskset(dev
, 0x004E, 0xFFC0, 0x0010);
1879 b43_phy_write(dev
, 0x002E, 0xC07F);
1880 b43_phy_set(dev
, 0x0036, 0x0400);
1882 b43_phy_set(dev
, 0x0036, 0x0200);
1883 b43_phy_set(dev
, 0x0036, 0x0400);
1884 b43_phy_mask(dev
, 0x005D, 0x7FFF);
1885 b43_phy_mask(dev
, 0x004F, 0xFFFE);
1886 b43_phy_maskset(dev
, 0x004E, 0xFFC0, 0x0010);
1887 b43_phy_write(dev
, 0x002E, 0xC07F);
1888 b43_phy_maskset(dev
, 0x047A, 0xFF0F, 0x0010);
1892 /* Hardware power control for G-PHY */
1893 static void b43_hardware_pctl_init_gphy(struct b43_wldev
*dev
)
1895 struct b43_phy
*phy
= &dev
->phy
;
1896 struct b43_phy_g
*gphy
= phy
->g
;
1898 if (!b43_has_hardware_pctl(dev
)) {
1899 /* No hardware power control */
1900 b43_hf_write(dev
, b43_hf_read(dev
) & ~B43_HF_HWPCTL
);
1904 b43_phy_maskset(dev
, 0x0036, 0xFFC0, (gphy
->tgt_idle_tssi
- gphy
->cur_idle_tssi
));
1905 b43_phy_maskset(dev
, 0x0478, 0xFF00, (gphy
->tgt_idle_tssi
- gphy
->cur_idle_tssi
));
1906 b43_gphy_tssi_power_lt_init(dev
);
1907 b43_gphy_gain_lt_init(dev
);
1908 b43_phy_mask(dev
, 0x0060, 0xFFBF);
1909 b43_phy_write(dev
, 0x0014, 0x0000);
1911 B43_WARN_ON(phy
->rev
< 6);
1912 b43_phy_set(dev
, 0x0478, 0x0800);
1913 b43_phy_mask(dev
, 0x0478, 0xFEFF);
1914 b43_phy_mask(dev
, 0x0801, 0xFFBF);
1916 b43_gphy_dc_lt_init(dev
, 1);
1918 /* Enable hardware pctl in firmware. */
1919 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_HWPCTL
);
1922 /* Initialize B/G PHY power control */
1923 static void b43_phy_init_pctl(struct b43_wldev
*dev
)
1925 struct b43_phy
*phy
= &dev
->phy
;
1926 struct b43_phy_g
*gphy
= phy
->g
;
1927 struct b43_rfatt old_rfatt
;
1928 struct b43_bbatt old_bbatt
;
1929 u8 old_tx_control
= 0;
1931 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
1933 if ((dev
->dev
->board_vendor
== SSB_BOARDVENDOR_BCM
) &&
1934 (dev
->dev
->board_type
== SSB_BOARD_BU4306
))
1937 b43_phy_write(dev
, 0x0028, 0x8018);
1939 /* This does something with the Analog... */
1940 b43_write16(dev
, B43_MMIO_PHY0
, b43_read16(dev
, B43_MMIO_PHY0
)
1945 b43_hardware_pctl_early_init(dev
);
1946 if (gphy
->cur_idle_tssi
== 0) {
1947 if (phy
->radio_ver
== 0x2050 && phy
->analog
== 0) {
1948 b43_radio_maskset(dev
, 0x0076, 0x00F7, 0x0084);
1950 struct b43_rfatt rfatt
;
1951 struct b43_bbatt bbatt
;
1953 memcpy(&old_rfatt
, &gphy
->rfatt
, sizeof(old_rfatt
));
1954 memcpy(&old_bbatt
, &gphy
->bbatt
, sizeof(old_bbatt
));
1955 old_tx_control
= gphy
->tx_control
;
1958 if (phy
->radio_rev
== 8) {
1960 rfatt
.with_padmix
= true;
1963 rfatt
.with_padmix
= false;
1965 b43_set_txpower_g(dev
, &bbatt
, &rfatt
, 0);
1967 b43_dummy_transmission(dev
, false, true);
1968 gphy
->cur_idle_tssi
= b43_phy_read(dev
, B43_PHY_ITSSI
);
1970 /* Current-Idle-TSSI sanity check. */
1971 if (abs(gphy
->cur_idle_tssi
- gphy
->tgt_idle_tssi
) >= 20) {
1973 "!WARNING! Idle-TSSI phy->cur_idle_tssi "
1974 "measuring failed. (cur=%d, tgt=%d). Disabling TX power "
1975 "adjustment.\n", gphy
->cur_idle_tssi
,
1976 gphy
->tgt_idle_tssi
);
1977 gphy
->cur_idle_tssi
= 0;
1980 if (phy
->radio_ver
== 0x2050 && phy
->analog
== 0) {
1981 b43_radio_mask(dev
, 0x0076, 0xFF7B);
1983 b43_set_txpower_g(dev
, &old_bbatt
,
1984 &old_rfatt
, old_tx_control
);
1987 b43_hardware_pctl_init_gphy(dev
);
1988 b43_shm_clear_tssi(dev
);
1991 static void b43_phy_inita(struct b43_wldev
*dev
)
1993 struct b43_phy
*phy
= &dev
->phy
;
1997 if (phy
->rev
>= 6) {
1998 if (b43_phy_read(dev
, B43_PHY_ENCORE
) & B43_PHY_ENCORE_EN
)
1999 b43_phy_set(dev
, B43_PHY_ENCORE
, 0x0010);
2001 b43_phy_mask(dev
, B43_PHY_ENCORE
, ~0x1010);
2006 if (dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_PACTRL
)
2007 b43_phy_maskset(dev
, B43_PHY_OFDM(0x6E), 0xE000, 0x3CF);
2010 static void b43_phy_initg(struct b43_wldev
*dev
)
2012 struct b43_phy
*phy
= &dev
->phy
;
2013 struct b43_phy_g
*gphy
= phy
->g
;
2017 b43_phy_initb5(dev
);
2019 b43_phy_initb6(dev
);
2021 if (phy
->rev
>= 2 || phy
->gmode
)
2024 if (phy
->rev
>= 2) {
2025 b43_phy_write(dev
, B43_PHY_ANALOGOVER
, 0);
2026 b43_phy_write(dev
, B43_PHY_ANALOGOVERVAL
, 0);
2028 if (phy
->rev
== 2) {
2029 b43_phy_write(dev
, B43_PHY_RFOVER
, 0);
2030 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xC0);
2033 b43_phy_write(dev
, B43_PHY_RFOVER
, 0x400);
2034 b43_phy_write(dev
, B43_PHY_PGACTL
, 0xC0);
2036 if (phy
->gmode
|| phy
->rev
>= 2) {
2037 tmp
= b43_phy_read(dev
, B43_PHY_VERSION_OFDM
);
2038 tmp
&= B43_PHYVER_VERSION
;
2039 if (tmp
== 3 || tmp
== 5) {
2040 b43_phy_write(dev
, B43_PHY_OFDM(0xC2), 0x1816);
2041 b43_phy_write(dev
, B43_PHY_OFDM(0xC3), 0x8006);
2044 b43_phy_maskset(dev
, B43_PHY_OFDM(0xCC), 0x00FF, 0x1F00);
2047 if ((phy
->rev
<= 2 && phy
->gmode
) || phy
->rev
>= 2)
2048 b43_phy_write(dev
, B43_PHY_OFDM(0x7E), 0x78);
2049 if (phy
->radio_rev
== 8) {
2050 b43_phy_set(dev
, B43_PHY_EXTG(0x01), 0x80);
2051 b43_phy_set(dev
, B43_PHY_OFDM(0x3E), 0x4);
2053 if (has_loopback_gain(phy
))
2054 b43_calc_loopback_gain(dev
);
2056 if (phy
->radio_rev
!= 8) {
2057 if (gphy
->initval
== 0xFFFF)
2058 gphy
->initval
= b43_radio_init2050(dev
);
2060 b43_radio_write16(dev
, 0x0078, gphy
->initval
);
2063 if (has_tx_magnification(phy
)) {
2064 b43_radio_write16(dev
, 0x52,
2065 (b43_radio_read16(dev
, 0x52) & 0xFF00)
2066 | gphy
->lo_control
->tx_bias
| gphy
->
2067 lo_control
->tx_magn
);
2069 b43_radio_maskset(dev
, 0x52, 0xFFF0, gphy
->lo_control
->tx_bias
);
2071 if (phy
->rev
>= 6) {
2072 b43_phy_maskset(dev
, B43_PHY_CCK(0x36), 0x0FFF, (gphy
->lo_control
->tx_bias
<< 12));
2074 if (dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_PACTRL
)
2075 b43_phy_write(dev
, B43_PHY_CCK(0x2E), 0x8075);
2077 b43_phy_write(dev
, B43_PHY_CCK(0x2E), 0x807F);
2079 b43_phy_write(dev
, B43_PHY_CCK(0x2F), 0x101);
2081 b43_phy_write(dev
, B43_PHY_CCK(0x2F), 0x202);
2082 if (phy
->gmode
|| phy
->rev
>= 2) {
2083 b43_lo_g_adjust(dev
);
2084 b43_phy_write(dev
, B43_PHY_LO_MASK
, 0x8078);
2087 if (!(dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_RSSI
)) {
2088 /* The specs state to update the NRSSI LT with
2089 * the value 0x7FFFFFFF here. I think that is some weird
2090 * compiler optimization in the original driver.
2091 * Essentially, what we do here is resetting all NRSSI LT
2092 * entries to -32 (see the clamp_val() in nrssi_hw_update())
2094 b43_nrssi_hw_update(dev
, 0xFFFF); //FIXME?
2095 b43_calc_nrssi_threshold(dev
);
2096 } else if (phy
->gmode
|| phy
->rev
>= 2) {
2097 if (gphy
->nrssi
[0] == -1000) {
2098 B43_WARN_ON(gphy
->nrssi
[1] != -1000);
2099 b43_calc_nrssi_slope(dev
);
2101 b43_calc_nrssi_threshold(dev
);
2103 if (phy
->radio_rev
== 8)
2104 b43_phy_write(dev
, B43_PHY_EXTG(0x05), 0x3230);
2105 b43_phy_init_pctl(dev
);
2106 /* FIXME: The spec says in the following if, the 0 should be replaced
2107 'if OFDM may not be used in the current locale'
2108 but OFDM is legal everywhere */
2109 if ((dev
->dev
->chip_id
== 0x4306
2110 && dev
->dev
->chip_pkg
== 2) || 0) {
2111 b43_phy_mask(dev
, B43_PHY_CRS0
, 0xBFFF);
2112 b43_phy_mask(dev
, B43_PHY_OFDM(0xC3), 0x7FFF);
2116 void b43_gphy_channel_switch(struct b43_wldev
*dev
,
2117 unsigned int channel
,
2118 bool synthetic_pu_workaround
)
2120 if (synthetic_pu_workaround
)
2121 b43_synth_pu_workaround(dev
, channel
);
2123 b43_write16(dev
, B43_MMIO_CHANNEL
, channel2freq_bg(channel
));
2125 if (channel
== 14) {
2126 if (dev
->dev
->bus_sprom
->country_code
==
2127 SSB_SPROM1CCODE_JAPAN
)
2129 b43_hf_read(dev
) & ~B43_HF_ACPR
);
2132 b43_hf_read(dev
) | B43_HF_ACPR
);
2133 b43_write16(dev
, B43_MMIO_CHANNEL_EXT
,
2134 b43_read16(dev
, B43_MMIO_CHANNEL_EXT
)
2137 b43_write16(dev
, B43_MMIO_CHANNEL_EXT
,
2138 b43_read16(dev
, B43_MMIO_CHANNEL_EXT
)
2143 static void default_baseband_attenuation(struct b43_wldev
*dev
,
2144 struct b43_bbatt
*bb
)
2146 struct b43_phy
*phy
= &dev
->phy
;
2148 if (phy
->radio_ver
== 0x2050 && phy
->radio_rev
< 6)
2154 static void default_radio_attenuation(struct b43_wldev
*dev
,
2155 struct b43_rfatt
*rf
)
2157 struct b43_bus_dev
*bdev
= dev
->dev
;
2158 struct b43_phy
*phy
= &dev
->phy
;
2160 rf
->with_padmix
= false;
2162 if (dev
->dev
->board_vendor
== SSB_BOARDVENDOR_BCM
&&
2163 dev
->dev
->board_type
== SSB_BOARD_BCM4309G
) {
2164 if (dev
->dev
->board_rev
< 0x43) {
2167 } else if (dev
->dev
->board_rev
< 0x51) {
2173 switch (phy
->radio_ver
) {
2175 switch (phy
->radio_rev
) {
2182 switch (phy
->radio_rev
) {
2187 if (phy
->type
== B43_PHYTYPE_G
) {
2188 if (bdev
->board_vendor
== SSB_BOARDVENDOR_BCM
2189 && bdev
->board_type
== SSB_BOARD_BCM4309G
2190 && bdev
->board_rev
>= 30)
2192 else if (bdev
->board_vendor
==
2194 && bdev
->board_type
==
2200 if (bdev
->board_vendor
== SSB_BOARDVENDOR_BCM
2201 && bdev
->board_type
== SSB_BOARD_BCM4309G
2202 && bdev
->board_rev
>= 30)
2209 if (phy
->type
== B43_PHYTYPE_G
) {
2210 if (bdev
->board_vendor
== SSB_BOARDVENDOR_BCM
2211 && bdev
->board_type
== SSB_BOARD_BCM4309G
2212 && bdev
->board_rev
>= 30)
2214 else if (bdev
->board_vendor
==
2216 && bdev
->board_type
==
2219 else if (bdev
->chip_id
== 0x4320)
2239 rf
->with_padmix
= true;
2250 static u16
default_tx_control(struct b43_wldev
*dev
)
2252 struct b43_phy
*phy
= &dev
->phy
;
2254 if (phy
->radio_ver
!= 0x2050)
2256 if (phy
->radio_rev
== 1)
2257 return B43_TXCTL_PA2DB
| B43_TXCTL_TXMIX
;
2258 if (phy
->radio_rev
< 6)
2259 return B43_TXCTL_PA2DB
;
2260 if (phy
->radio_rev
== 8)
2261 return B43_TXCTL_TXMIX
;
2265 static u8
b43_gphy_aci_detect(struct b43_wldev
*dev
, u8 channel
)
2267 struct b43_phy
*phy
= &dev
->phy
;
2268 struct b43_phy_g
*gphy
= phy
->g
;
2270 u16 saved
, rssi
, temp
;
2273 saved
= b43_phy_read(dev
, 0x0403);
2274 b43_switch_channel(dev
, channel
);
2275 b43_phy_write(dev
, 0x0403, (saved
& 0xFFF8) | 5);
2276 if (gphy
->aci_hw_rssi
)
2277 rssi
= b43_phy_read(dev
, 0x048A) & 0x3F;
2279 rssi
= saved
& 0x3F;
2280 /* clamp temp to signed 5bit */
2283 for (i
= 0; i
< 100; i
++) {
2284 temp
= (b43_phy_read(dev
, 0x047F) >> 8) & 0x3F;
2292 b43_phy_write(dev
, 0x0403, saved
);
2297 static u8
b43_gphy_aci_scan(struct b43_wldev
*dev
)
2299 struct b43_phy
*phy
= &dev
->phy
;
2301 unsigned int channel
= phy
->channel
;
2302 unsigned int i
, j
, start
, end
;
2304 if (!((phy
->type
== B43_PHYTYPE_G
) && (phy
->rev
> 0)))
2308 b43_radio_lock(dev
);
2309 b43_phy_mask(dev
, 0x0802, 0xFFFC);
2310 b43_phy_mask(dev
, B43_PHY_G_CRS
, 0x7FFF);
2311 b43_set_all_gains(dev
, 3, 8, 1);
2313 start
= (channel
- 5 > 0) ? channel
- 5 : 1;
2314 end
= (channel
+ 5 < 14) ? channel
+ 5 : 13;
2316 for (i
= start
; i
<= end
; i
++) {
2317 if (abs(channel
- i
) > 2)
2318 ret
[i
- 1] = b43_gphy_aci_detect(dev
, i
);
2320 b43_switch_channel(dev
, channel
);
2321 b43_phy_maskset(dev
, 0x0802, 0xFFFC, 0x0003);
2322 b43_phy_mask(dev
, 0x0403, 0xFFF8);
2323 b43_phy_set(dev
, B43_PHY_G_CRS
, 0x8000);
2324 b43_set_original_gains(dev
);
2325 for (i
= 0; i
< 13; i
++) {
2328 end
= (i
+ 5 < 13) ? i
+ 5 : 13;
2329 for (j
= i
; j
< end
; j
++)
2332 b43_radio_unlock(dev
);
2333 b43_phy_unlock(dev
);
2335 return ret
[channel
- 1];
2338 static s32
b43_tssi2dbm_ad(s32 num
, s32 den
)
2343 return (num
+ den
/ 2) / den
;
2346 static s8
b43_tssi2dbm_entry(s8 entry
[], u8 index
,
2347 s16 pab0
, s16 pab1
, s16 pab2
)
2349 s32 m1
, m2
, f
= 256, q
, delta
;
2352 m1
= b43_tssi2dbm_ad(16 * pab0
+ index
* pab1
, 32);
2353 m2
= max(b43_tssi2dbm_ad(32768 + index
* pab2
, 256), 1);
2357 q
= b43_tssi2dbm_ad(f
* 4096 -
2358 b43_tssi2dbm_ad(m2
* f
, 16) * f
, 2048);
2362 } while (delta
>= 2);
2363 entry
[index
] = clamp_val(b43_tssi2dbm_ad(m1
* f
, 8192), -127, 128);
2367 u8
*b43_generate_dyn_tssi2dbm_tab(struct b43_wldev
*dev
,
2368 s16 pab0
, s16 pab1
, s16 pab2
)
2374 tab
= kmalloc(64, GFP_KERNEL
);
2376 b43err(dev
->wl
, "Could not allocate memory "
2377 "for tssi2dbm table\n");
2380 for (i
= 0; i
< 64; i
++) {
2381 err
= b43_tssi2dbm_entry(tab
, i
, pab0
, pab1
, pab2
);
2383 b43err(dev
->wl
, "Could not generate "
2384 "tssi2dBm table\n");
2393 /* Initialise the TSSI->dBm lookup table */
2394 static int b43_gphy_init_tssi2dbm_table(struct b43_wldev
*dev
)
2396 struct b43_phy
*phy
= &dev
->phy
;
2397 struct b43_phy_g
*gphy
= phy
->g
;
2398 s16 pab0
, pab1
, pab2
;
2400 pab0
= (s16
) (dev
->dev
->bus_sprom
->pa0b0
);
2401 pab1
= (s16
) (dev
->dev
->bus_sprom
->pa0b1
);
2402 pab2
= (s16
) (dev
->dev
->bus_sprom
->pa0b2
);
2404 B43_WARN_ON((dev
->dev
->chip_id
== 0x4301) &&
2405 (phy
->radio_ver
!= 0x2050)); /* Not supported anymore */
2407 gphy
->dyn_tssi_tbl
= false;
2409 if (pab0
!= 0 && pab1
!= 0 && pab2
!= 0 &&
2410 pab0
!= -1 && pab1
!= -1 && pab2
!= -1) {
2411 /* The pabX values are set in SPROM. Use them. */
2412 if ((s8
) dev
->dev
->bus_sprom
->itssi_bg
!= 0 &&
2413 (s8
) dev
->dev
->bus_sprom
->itssi_bg
!= -1) {
2414 gphy
->tgt_idle_tssi
=
2415 (s8
) (dev
->dev
->bus_sprom
->itssi_bg
);
2417 gphy
->tgt_idle_tssi
= 62;
2418 gphy
->tssi2dbm
= b43_generate_dyn_tssi2dbm_tab(dev
, pab0
,
2420 if (!gphy
->tssi2dbm
)
2422 gphy
->dyn_tssi_tbl
= true;
2424 /* pabX values not set in SPROM. */
2425 gphy
->tgt_idle_tssi
= 52;
2426 gphy
->tssi2dbm
= b43_tssi2dbm_g_table
;
2432 static int b43_gphy_op_allocate(struct b43_wldev
*dev
)
2434 struct b43_phy_g
*gphy
;
2435 struct b43_txpower_lo_control
*lo
;
2438 gphy
= kzalloc(sizeof(*gphy
), GFP_KERNEL
);
2445 lo
= kzalloc(sizeof(*lo
), GFP_KERNEL
);
2450 gphy
->lo_control
= lo
;
2452 err
= b43_gphy_init_tssi2dbm_table(dev
);
2466 static void b43_gphy_op_prepare_structs(struct b43_wldev
*dev
)
2468 struct b43_phy
*phy
= &dev
->phy
;
2469 struct b43_phy_g
*gphy
= phy
->g
;
2470 const void *tssi2dbm
;
2472 struct b43_txpower_lo_control
*lo
;
2475 /* tssi2dbm table is constant, so it is initialized at alloc time.
2476 * Save a copy of the pointer. */
2477 tssi2dbm
= gphy
->tssi2dbm
;
2478 tgt_idle_tssi
= gphy
->tgt_idle_tssi
;
2479 /* Save the LO pointer. */
2480 lo
= gphy
->lo_control
;
2482 /* Zero out the whole PHY structure. */
2483 memset(gphy
, 0, sizeof(*gphy
));
2485 /* Restore pointers. */
2486 gphy
->tssi2dbm
= tssi2dbm
;
2487 gphy
->tgt_idle_tssi
= tgt_idle_tssi
;
2488 gphy
->lo_control
= lo
;
2490 memset(gphy
->minlowsig
, 0xFF, sizeof(gphy
->minlowsig
));
2493 for (i
= 0; i
< ARRAY_SIZE(gphy
->nrssi
); i
++)
2494 gphy
->nrssi
[i
] = -1000;
2495 for (i
= 0; i
< ARRAY_SIZE(gphy
->nrssi_lt
); i
++)
2496 gphy
->nrssi_lt
[i
] = i
;
2498 gphy
->lofcal
= 0xFFFF;
2499 gphy
->initval
= 0xFFFF;
2501 gphy
->interfmode
= B43_INTERFMODE_NONE
;
2503 /* OFDM-table address caching. */
2504 gphy
->ofdmtab_addr_direction
= B43_OFDMTAB_DIRECTION_UNKNOWN
;
2506 gphy
->average_tssi
= 0xFF;
2508 /* Local Osciallator structure */
2510 INIT_LIST_HEAD(&lo
->calib_list
);
2513 static void b43_gphy_op_free(struct b43_wldev
*dev
)
2515 struct b43_phy
*phy
= &dev
->phy
;
2516 struct b43_phy_g
*gphy
= phy
->g
;
2518 kfree(gphy
->lo_control
);
2520 if (gphy
->dyn_tssi_tbl
)
2521 kfree(gphy
->tssi2dbm
);
2522 gphy
->dyn_tssi_tbl
= false;
2523 gphy
->tssi2dbm
= NULL
;
2529 static int b43_gphy_op_prepare_hardware(struct b43_wldev
*dev
)
2531 struct b43_phy
*phy
= &dev
->phy
;
2532 struct b43_phy_g
*gphy
= phy
->g
;
2533 struct b43_txpower_lo_control
*lo
= gphy
->lo_control
;
2535 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
2537 default_baseband_attenuation(dev
, &gphy
->bbatt
);
2538 default_radio_attenuation(dev
, &gphy
->rfatt
);
2539 gphy
->tx_control
= (default_tx_control(dev
) << 4);
2540 generate_rfatt_list(dev
, &lo
->rfatt_list
);
2541 generate_bbatt_list(dev
, &lo
->bbatt_list
);
2543 /* Commit previous writes */
2544 b43_read32(dev
, B43_MMIO_MACCTL
);
2546 if (phy
->rev
== 1) {
2547 /* Workaround: Temporarly disable gmode through the early init
2548 * phase, as the gmode stuff is not needed for phy rev 1 */
2550 b43_wireless_core_reset(dev
, 0);
2553 b43_wireless_core_reset(dev
, 1);
2559 static int b43_gphy_op_init(struct b43_wldev
*dev
)
2566 static void b43_gphy_op_exit(struct b43_wldev
*dev
)
2568 b43_lo_g_cleanup(dev
);
2571 static u16
b43_gphy_op_read(struct b43_wldev
*dev
, u16 reg
)
2573 b43_write16f(dev
, B43_MMIO_PHY_CONTROL
, reg
);
2574 return b43_read16(dev
, B43_MMIO_PHY_DATA
);
2577 static void b43_gphy_op_write(struct b43_wldev
*dev
, u16 reg
, u16 value
)
2579 b43_write16f(dev
, B43_MMIO_PHY_CONTROL
, reg
);
2580 b43_write16(dev
, B43_MMIO_PHY_DATA
, value
);
2583 static u16
b43_gphy_op_radio_read(struct b43_wldev
*dev
, u16 reg
)
2585 /* Register 1 is a 32-bit register. */
2586 B43_WARN_ON(reg
== 1);
2587 /* G-PHY needs 0x80 for read access. */
2590 b43_write16f(dev
, B43_MMIO_RADIO_CONTROL
, reg
);
2591 return b43_read16(dev
, B43_MMIO_RADIO_DATA_LOW
);
2594 static void b43_gphy_op_radio_write(struct b43_wldev
*dev
, u16 reg
, u16 value
)
2596 /* Register 1 is a 32-bit register. */
2597 B43_WARN_ON(reg
== 1);
2599 b43_write16f(dev
, B43_MMIO_RADIO_CONTROL
, reg
);
2600 b43_write16(dev
, B43_MMIO_RADIO_DATA_LOW
, value
);
2603 static bool b43_gphy_op_supports_hwpctl(struct b43_wldev
*dev
)
2605 return (dev
->phy
.rev
>= 6);
2608 static void b43_gphy_op_software_rfkill(struct b43_wldev
*dev
,
2611 struct b43_phy
*phy
= &dev
->phy
;
2612 struct b43_phy_g
*gphy
= phy
->g
;
2613 unsigned int channel
;
2622 b43_phy_write(dev
, 0x0015, 0x8000);
2623 b43_phy_write(dev
, 0x0015, 0xCC00);
2624 b43_phy_write(dev
, 0x0015, (phy
->gmode
? 0x00C0 : 0x0000));
2625 if (gphy
->radio_off_context
.valid
) {
2626 /* Restore the RFover values. */
2627 b43_phy_write(dev
, B43_PHY_RFOVER
,
2628 gphy
->radio_off_context
.rfover
);
2629 b43_phy_write(dev
, B43_PHY_RFOVERVAL
,
2630 gphy
->radio_off_context
.rfoverval
);
2631 gphy
->radio_off_context
.valid
= false;
2633 channel
= phy
->channel
;
2634 b43_gphy_channel_switch(dev
, 6, 1);
2635 b43_gphy_channel_switch(dev
, channel
, 0);
2637 /* Turn radio OFF */
2638 u16 rfover
, rfoverval
;
2640 rfover
= b43_phy_read(dev
, B43_PHY_RFOVER
);
2641 rfoverval
= b43_phy_read(dev
, B43_PHY_RFOVERVAL
);
2642 gphy
->radio_off_context
.rfover
= rfover
;
2643 gphy
->radio_off_context
.rfoverval
= rfoverval
;
2644 gphy
->radio_off_context
.valid
= true;
2645 b43_phy_write(dev
, B43_PHY_RFOVER
, rfover
| 0x008C);
2646 b43_phy_write(dev
, B43_PHY_RFOVERVAL
, rfoverval
& 0xFF73);
2650 static int b43_gphy_op_switch_channel(struct b43_wldev
*dev
,
2651 unsigned int new_channel
)
2653 if ((new_channel
< 1) || (new_channel
> 14))
2655 b43_gphy_channel_switch(dev
, new_channel
, 0);
2660 static unsigned int b43_gphy_op_get_default_chan(struct b43_wldev
*dev
)
2662 return 1; /* Default to channel 1 */
2665 static void b43_gphy_op_set_rx_antenna(struct b43_wldev
*dev
, int antenna
)
2667 struct b43_phy
*phy
= &dev
->phy
;
2671 if (antenna
== B43_ANTENNA_AUTO0
|| antenna
== B43_ANTENNA_AUTO1
)
2674 b43_hf_write(dev
, b43_hf_read(dev
) & ~B43_HF_ANTDIVHELP
);
2676 b43_phy_maskset(dev
, B43_PHY_BBANDCFG
, ~B43_PHY_BBANDCFG_RXANT
,
2677 (autodiv
? B43_ANTENNA_AUTO1
: antenna
) <<
2678 B43_PHY_BBANDCFG_RXANT_SHIFT
);
2681 tmp
= b43_phy_read(dev
, B43_PHY_ANTDWELL
);
2682 if (antenna
== B43_ANTENNA_AUTO1
)
2683 tmp
&= ~B43_PHY_ANTDWELL_AUTODIV1
;
2685 tmp
|= B43_PHY_ANTDWELL_AUTODIV1
;
2686 b43_phy_write(dev
, B43_PHY_ANTDWELL
, tmp
);
2689 tmp
= b43_phy_read(dev
, B43_PHY_ANTWRSETT
);
2691 tmp
|= B43_PHY_ANTWRSETT_ARXDIV
;
2693 tmp
&= ~B43_PHY_ANTWRSETT_ARXDIV
;
2694 b43_phy_write(dev
, B43_PHY_ANTWRSETT
, tmp
);
2697 b43_phy_set(dev
, B43_PHY_ANTWRSETT
, B43_PHY_ANTWRSETT_ARXDIV
);
2699 b43_phy_mask(dev
, B43_PHY_ANTWRSETT
,
2700 B43_PHY_ANTWRSETT_ARXDIV
);
2703 if (phy
->rev
>= 2) {
2704 b43_phy_set(dev
, B43_PHY_OFDM61
, B43_PHY_OFDM61_10
);
2705 b43_phy_maskset(dev
, B43_PHY_DIVSRCHGAINBACK
, 0xFF00, 0x15);
2708 b43_phy_write(dev
, B43_PHY_ADIVRELATED
, 8);
2710 b43_phy_maskset(dev
, B43_PHY_ADIVRELATED
, 0xFF00, 8);
2713 b43_phy_write(dev
, B43_PHY_OFDM9B
, 0xDC);
2715 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_ANTDIVHELP
);
2718 static int b43_gphy_op_interf_mitigation(struct b43_wldev
*dev
,
2719 enum b43_interference_mitigation mode
)
2721 struct b43_phy
*phy
= &dev
->phy
;
2722 struct b43_phy_g
*gphy
= phy
->g
;
2725 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
2726 if ((phy
->rev
== 0) || (!phy
->gmode
))
2729 gphy
->aci_wlan_automatic
= false;
2731 case B43_INTERFMODE_AUTOWLAN
:
2732 gphy
->aci_wlan_automatic
= true;
2733 if (gphy
->aci_enable
)
2734 mode
= B43_INTERFMODE_MANUALWLAN
;
2736 mode
= B43_INTERFMODE_NONE
;
2738 case B43_INTERFMODE_NONE
:
2739 case B43_INTERFMODE_NONWLAN
:
2740 case B43_INTERFMODE_MANUALWLAN
:
2746 currentmode
= gphy
->interfmode
;
2747 if (currentmode
== mode
)
2749 if (currentmode
!= B43_INTERFMODE_NONE
)
2750 b43_radio_interference_mitigation_disable(dev
, currentmode
);
2752 if (mode
== B43_INTERFMODE_NONE
) {
2753 gphy
->aci_enable
= false;
2754 gphy
->aci_hw_rssi
= false;
2756 b43_radio_interference_mitigation_enable(dev
, mode
);
2757 gphy
->interfmode
= mode
;
2762 /* http://bcm-specs.sipsolutions.net/EstimatePowerOut
2763 * This function converts a TSSI value to dBm in Q5.2
2765 static s8
b43_gphy_estimate_power_out(struct b43_wldev
*dev
, s8 tssi
)
2767 struct b43_phy_g
*gphy
= dev
->phy
.g
;
2771 tmp
= (gphy
->tgt_idle_tssi
- gphy
->cur_idle_tssi
+ tssi
);
2772 tmp
= clamp_val(tmp
, 0x00, 0x3F);
2773 dbm
= gphy
->tssi2dbm
[tmp
];
2778 static void b43_put_attenuation_into_ranges(struct b43_wldev
*dev
,
2779 int *_bbatt
, int *_rfatt
)
2781 int rfatt
= *_rfatt
;
2782 int bbatt
= *_bbatt
;
2783 struct b43_txpower_lo_control
*lo
= dev
->phy
.g
->lo_control
;
2785 /* Get baseband and radio attenuation values into their permitted ranges.
2786 * Radio attenuation affects power level 4 times as much as baseband. */
2788 /* Range constants */
2789 const int rf_min
= lo
->rfatt_list
.min_val
;
2790 const int rf_max
= lo
->rfatt_list
.max_val
;
2791 const int bb_min
= lo
->bbatt_list
.min_val
;
2792 const int bb_max
= lo
->bbatt_list
.max_val
;
2795 if (rfatt
> rf_max
&& bbatt
> bb_max
- 4)
2796 break; /* Can not get it into ranges */
2797 if (rfatt
< rf_min
&& bbatt
< bb_min
+ 4)
2798 break; /* Can not get it into ranges */
2799 if (bbatt
> bb_max
&& rfatt
> rf_max
- 1)
2800 break; /* Can not get it into ranges */
2801 if (bbatt
< bb_min
&& rfatt
< rf_min
+ 1)
2802 break; /* Can not get it into ranges */
2804 if (bbatt
> bb_max
) {
2809 if (bbatt
< bb_min
) {
2814 if (rfatt
> rf_max
) {
2819 if (rfatt
< rf_min
) {
2827 *_rfatt
= clamp_val(rfatt
, rf_min
, rf_max
);
2828 *_bbatt
= clamp_val(bbatt
, bb_min
, bb_max
);
2831 static void b43_gphy_op_adjust_txpower(struct b43_wldev
*dev
)
2833 struct b43_phy
*phy
= &dev
->phy
;
2834 struct b43_phy_g
*gphy
= phy
->g
;
2838 b43_mac_suspend(dev
);
2840 /* Calculate the new attenuation values. */
2841 bbatt
= gphy
->bbatt
.att
;
2842 bbatt
+= gphy
->bbatt_delta
;
2843 rfatt
= gphy
->rfatt
.att
;
2844 rfatt
+= gphy
->rfatt_delta
;
2846 b43_put_attenuation_into_ranges(dev
, &bbatt
, &rfatt
);
2847 tx_control
= gphy
->tx_control
;
2848 if ((phy
->radio_ver
== 0x2050) && (phy
->radio_rev
== 2)) {
2850 if (tx_control
== 0) {
2856 } else if (dev
->dev
->bus_sprom
->
2859 bbatt
+= 4 * (rfatt
- 2);
2862 } else if (rfatt
> 4 && tx_control
) {
2873 /* Save the control values */
2874 gphy
->tx_control
= tx_control
;
2875 b43_put_attenuation_into_ranges(dev
, &bbatt
, &rfatt
);
2876 gphy
->rfatt
.att
= rfatt
;
2877 gphy
->bbatt
.att
= bbatt
;
2879 if (b43_debug(dev
, B43_DBG_XMITPOWER
))
2880 b43dbg(dev
->wl
, "Adjusting TX power\n");
2882 /* Adjust the hardware */
2884 b43_radio_lock(dev
);
2885 b43_set_txpower_g(dev
, &gphy
->bbatt
, &gphy
->rfatt
,
2887 b43_radio_unlock(dev
);
2888 b43_phy_unlock(dev
);
2890 b43_mac_enable(dev
);
2893 static enum b43_txpwr_result
b43_gphy_op_recalc_txpower(struct b43_wldev
*dev
,
2896 struct b43_phy
*phy
= &dev
->phy
;
2897 struct b43_phy_g
*gphy
= phy
->g
;
2898 unsigned int average_tssi
;
2899 int cck_result
, ofdm_result
;
2900 int estimated_pwr
, desired_pwr
, pwr_adjust
;
2901 int rfatt_delta
, bbatt_delta
;
2902 unsigned int max_pwr
;
2904 /* First get the average TSSI */
2905 cck_result
= b43_phy_shm_tssi_read(dev
, B43_SHM_SH_TSSI_CCK
);
2906 ofdm_result
= b43_phy_shm_tssi_read(dev
, B43_SHM_SH_TSSI_OFDM_G
);
2907 if ((cck_result
< 0) && (ofdm_result
< 0)) {
2908 /* No TSSI information available */
2910 goto no_adjustment_needed
;
2915 average_tssi
= ofdm_result
;
2916 else if (ofdm_result
< 0)
2917 average_tssi
= cck_result
;
2919 average_tssi
= (cck_result
+ ofdm_result
) / 2;
2920 /* Merge the average with the stored value. */
2921 if (likely(gphy
->average_tssi
!= 0xFF))
2922 average_tssi
= (average_tssi
+ gphy
->average_tssi
) / 2;
2923 gphy
->average_tssi
= average_tssi
;
2924 B43_WARN_ON(average_tssi
>= B43_TSSI_MAX
);
2926 /* Estimate the TX power emission based on the TSSI */
2927 estimated_pwr
= b43_gphy_estimate_power_out(dev
, average_tssi
);
2929 B43_WARN_ON(phy
->type
!= B43_PHYTYPE_G
);
2930 max_pwr
= dev
->dev
->bus_sprom
->maxpwr_bg
;
2931 if (dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_PACTRL
)
2932 max_pwr
-= 3; /* minus 0.75 */
2933 if (unlikely(max_pwr
>= INT_TO_Q52(30/*dBm*/))) {
2935 "Invalid max-TX-power value in SPROM.\n");
2936 max_pwr
= INT_TO_Q52(20); /* fake it */
2937 dev
->dev
->bus_sprom
->maxpwr_bg
= max_pwr
;
2940 /* Get desired power (in Q5.2) */
2941 if (phy
->desired_txpower
< 0)
2942 desired_pwr
= INT_TO_Q52(0);
2944 desired_pwr
= INT_TO_Q52(phy
->desired_txpower
);
2945 /* And limit it. max_pwr already is Q5.2 */
2946 desired_pwr
= clamp_val(desired_pwr
, 0, max_pwr
);
2947 if (b43_debug(dev
, B43_DBG_XMITPOWER
)) {
2949 "[TX power] current = " Q52_FMT
2950 " dBm, desired = " Q52_FMT
2951 " dBm, max = " Q52_FMT
"\n",
2952 Q52_ARG(estimated_pwr
),
2953 Q52_ARG(desired_pwr
),
2957 /* Calculate the adjustment delta. */
2958 pwr_adjust
= desired_pwr
- estimated_pwr
;
2959 if (pwr_adjust
== 0)
2960 goto no_adjustment_needed
;
2962 /* RF attenuation delta. */
2963 rfatt_delta
= ((pwr_adjust
+ 7) / 8);
2964 /* Lower attenuation => Bigger power output. Negate it. */
2965 rfatt_delta
= -rfatt_delta
;
2967 /* Baseband attenuation delta. */
2968 bbatt_delta
= pwr_adjust
/ 2;
2969 /* Lower attenuation => Bigger power output. Negate it. */
2970 bbatt_delta
= -bbatt_delta
;
2971 /* RF att affects power level 4 times as much as
2972 * Baseband attennuation. Subtract it. */
2973 bbatt_delta
-= 4 * rfatt_delta
;
2976 if (b43_debug(dev
, B43_DBG_XMITPOWER
)) {
2977 int dbm
= pwr_adjust
< 0 ? -pwr_adjust
: pwr_adjust
;
2979 "[TX power deltas] %s" Q52_FMT
" dBm => "
2980 "bbatt-delta = %d, rfatt-delta = %d\n",
2981 (pwr_adjust
< 0 ? "-" : ""), Q52_ARG(dbm
),
2982 bbatt_delta
, rfatt_delta
);
2986 /* So do we finally need to adjust something in hardware? */
2987 if ((rfatt_delta
== 0) && (bbatt_delta
== 0))
2988 goto no_adjustment_needed
;
2990 /* Save the deltas for later when we adjust the power. */
2991 gphy
->bbatt_delta
= bbatt_delta
;
2992 gphy
->rfatt_delta
= rfatt_delta
;
2994 /* We need to adjust the TX power on the device. */
2995 return B43_TXPWR_RES_NEED_ADJUST
;
2997 no_adjustment_needed
:
2998 return B43_TXPWR_RES_DONE
;
3001 static void b43_gphy_op_pwork_15sec(struct b43_wldev
*dev
)
3003 struct b43_phy
*phy
= &dev
->phy
;
3004 struct b43_phy_g
*gphy
= phy
->g
;
3006 b43_mac_suspend(dev
);
3007 //TODO: update_aci_moving_average
3008 if (gphy
->aci_enable
&& gphy
->aci_wlan_automatic
) {
3009 if (!gphy
->aci_enable
&& 1 /*TODO: not scanning? */ ) {
3010 if (0 /*TODO: bunch of conditions */ ) {
3011 phy
->ops
->interf_mitigation(dev
,
3012 B43_INTERFMODE_MANUALWLAN
);
3014 } else if (0 /*TODO*/) {
3015 if (/*(aci_average > 1000) &&*/ !b43_gphy_aci_scan(dev
))
3016 phy
->ops
->interf_mitigation(dev
, B43_INTERFMODE_NONE
);
3018 } else if (gphy
->interfmode
== B43_INTERFMODE_NONWLAN
&&
3020 //TODO: implement rev1 workaround
3022 b43_lo_g_maintenance_work(dev
);
3023 b43_mac_enable(dev
);
3026 static void b43_gphy_op_pwork_60sec(struct b43_wldev
*dev
)
3028 struct b43_phy
*phy
= &dev
->phy
;
3030 if (!(dev
->dev
->bus_sprom
->boardflags_lo
& B43_BFL_RSSI
))
3033 b43_mac_suspend(dev
);
3034 b43_calc_nrssi_slope(dev
);
3035 if ((phy
->radio_ver
== 0x2050) && (phy
->radio_rev
== 8)) {
3036 u8 old_chan
= phy
->channel
;
3038 /* VCO Calibration */
3040 b43_switch_channel(dev
, 1);
3042 b43_switch_channel(dev
, 13);
3043 b43_switch_channel(dev
, old_chan
);
3045 b43_mac_enable(dev
);
3048 const struct b43_phy_operations b43_phyops_g
= {
3049 .allocate
= b43_gphy_op_allocate
,
3050 .free
= b43_gphy_op_free
,
3051 .prepare_structs
= b43_gphy_op_prepare_structs
,
3052 .prepare_hardware
= b43_gphy_op_prepare_hardware
,
3053 .init
= b43_gphy_op_init
,
3054 .exit
= b43_gphy_op_exit
,
3055 .phy_read
= b43_gphy_op_read
,
3056 .phy_write
= b43_gphy_op_write
,
3057 .radio_read
= b43_gphy_op_radio_read
,
3058 .radio_write
= b43_gphy_op_radio_write
,
3059 .supports_hwpctl
= b43_gphy_op_supports_hwpctl
,
3060 .software_rfkill
= b43_gphy_op_software_rfkill
,
3061 .switch_analog
= b43_phyop_switch_analog_generic
,
3062 .switch_channel
= b43_gphy_op_switch_channel
,
3063 .get_default_chan
= b43_gphy_op_get_default_chan
,
3064 .set_rx_antenna
= b43_gphy_op_set_rx_antenna
,
3065 .interf_mitigation
= b43_gphy_op_interf_mitigation
,
3066 .recalc_txpower
= b43_gphy_op_recalc_txpower
,
3067 .adjust_txpower
= b43_gphy_op_adjust_txpower
,
3068 .pwork_15sec
= b43_gphy_op_pwork_15sec
,
3069 .pwork_60sec
= b43_gphy_op_pwork_60sec
,