3 Broadcom B43 wireless driver
4 IEEE 802.11n PHY support
6 Copyright (c) 2008 Michael Buesch <m@bues.ch>
7 Copyright (c) 2010-2011 Rafał Miłecki <zajec5@gmail.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
32 #include "tables_nphy.h"
33 #include "radio_2055.h"
34 #include "radio_2056.h"
35 #include "radio_2057.h"
45 struct nphy_iqcal_params
{
63 enum b43_nphy_rf_sequence
{
67 B43_RFSEQ_UPDATE_GAINH
,
68 B43_RFSEQ_UPDATE_GAINL
,
69 B43_RFSEQ_UPDATE_GAINU
,
72 enum n_intc_override
{
73 N_INTC_OVERRIDE_OFF
= 0,
74 N_INTC_OVERRIDE_TRSW
= 1,
75 N_INTC_OVERRIDE_PA
= 2,
76 N_INTC_OVERRIDE_EXT_LNA_PU
= 3,
77 N_INTC_OVERRIDE_EXT_LNA_GAIN
= 4,
95 static inline bool b43_nphy_ipa(struct b43_wldev
*dev
)
97 enum ieee80211_band band
= b43_current_band(dev
->wl
);
98 return ((dev
->phy
.n
->ipa2g_on
&& band
== IEEE80211_BAND_2GHZ
) ||
99 (dev
->phy
.n
->ipa5g_on
&& band
== IEEE80211_BAND_5GHZ
));
102 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCoreGetState */
103 static u8
b43_nphy_get_rx_core_state(struct b43_wldev
*dev
)
105 return (b43_phy_read(dev
, B43_NPHY_RFSEQCA
) & B43_NPHY_RFSEQCA_RXEN
) >>
106 B43_NPHY_RFSEQCA_RXEN_SHIFT
;
109 /**************************************************
110 * RF (just without b43_nphy_rf_ctl_intc_override)
111 **************************************************/
113 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ForceRFSeq */
114 static void b43_nphy_force_rf_sequence(struct b43_wldev
*dev
,
115 enum b43_nphy_rf_sequence seq
)
117 static const u16 trigger
[] = {
118 [B43_RFSEQ_RX2TX
] = B43_NPHY_RFSEQTR_RX2TX
,
119 [B43_RFSEQ_TX2RX
] = B43_NPHY_RFSEQTR_TX2RX
,
120 [B43_RFSEQ_RESET2RX
] = B43_NPHY_RFSEQTR_RST2RX
,
121 [B43_RFSEQ_UPDATE_GAINH
] = B43_NPHY_RFSEQTR_UPGH
,
122 [B43_RFSEQ_UPDATE_GAINL
] = B43_NPHY_RFSEQTR_UPGL
,
123 [B43_RFSEQ_UPDATE_GAINU
] = B43_NPHY_RFSEQTR_UPGU
,
126 u16 seq_mode
= b43_phy_read(dev
, B43_NPHY_RFSEQMODE
);
128 B43_WARN_ON(seq
>= ARRAY_SIZE(trigger
));
130 b43_phy_set(dev
, B43_NPHY_RFSEQMODE
,
131 B43_NPHY_RFSEQMODE_CAOVER
| B43_NPHY_RFSEQMODE_TROVER
);
132 b43_phy_set(dev
, B43_NPHY_RFSEQTR
, trigger
[seq
]);
133 for (i
= 0; i
< 200; i
++) {
134 if (!(b43_phy_read(dev
, B43_NPHY_RFSEQST
) & trigger
[seq
]))
138 b43err(dev
->wl
, "RF sequence status timeout\n");
140 b43_phy_write(dev
, B43_NPHY_RFSEQMODE
, seq_mode
);
143 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlOverrideRev7 */
144 static void b43_nphy_rf_ctl_override_rev7(struct b43_wldev
*dev
, u16 field
,
145 u16 value
, u8 core
, bool off
,
148 const struct nphy_rf_control_override_rev7
*e
;
149 u16 en_addrs
[3][2] = {
150 { 0x0E7, 0x0EC }, { 0x342, 0x343 }, { 0x346, 0x347 }
157 /* Remember: we can get NULL! */
158 e
= b43_nphy_get_rf_ctl_over_rev7(dev
, field
, override
);
160 for (i
= 0; i
< 2; i
++) {
161 if (override
>= ARRAY_SIZE(en_addrs
)) {
162 b43err(dev
->wl
, "Invalid override value %d\n", override
);
165 en_addr
= en_addrs
[override
][i
];
168 val_addr
= (i
== 0) ? e
->val_addr_core0
: e
->val_addr_core1
;
171 b43_phy_mask(dev
, en_addr
, ~en_mask
);
172 if (e
) /* Do it safer, better than wl */
173 b43_phy_mask(dev
, val_addr
, ~e
->val_mask
);
175 if (!core
|| (core
& (1 << i
))) {
176 b43_phy_set(dev
, en_addr
, en_mask
);
178 b43_phy_maskset(dev
, val_addr
, ~e
->val_mask
, (value
<< e
->val_shift
));
184 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlOverride */
185 static void b43_nphy_rf_ctl_override(struct b43_wldev
*dev
, u16 field
,
186 u16 value
, u8 core
, bool off
)
189 u8 index
= fls(field
);
190 u8 addr
, en_addr
, val_addr
;
191 /* we expect only one bit set */
192 B43_WARN_ON(field
& (~(1 << (index
- 1))));
194 if (dev
->phy
.rev
>= 3) {
195 const struct nphy_rf_control_override_rev3
*rf_ctrl
;
196 for (i
= 0; i
< 2; i
++) {
197 if (index
== 0 || index
== 16) {
199 "Unsupported RF Ctrl Override call\n");
203 rf_ctrl
= &tbl_rf_control_override_rev3
[index
- 1];
204 en_addr
= B43_PHY_N((i
== 0) ?
205 rf_ctrl
->en_addr0
: rf_ctrl
->en_addr1
);
206 val_addr
= B43_PHY_N((i
== 0) ?
207 rf_ctrl
->val_addr0
: rf_ctrl
->val_addr1
);
210 b43_phy_mask(dev
, en_addr
, ~(field
));
211 b43_phy_mask(dev
, val_addr
,
212 ~(rf_ctrl
->val_mask
));
214 if (core
== 0 || ((1 << i
) & core
)) {
215 b43_phy_set(dev
, en_addr
, field
);
216 b43_phy_maskset(dev
, val_addr
,
217 ~(rf_ctrl
->val_mask
),
218 (value
<< rf_ctrl
->val_shift
));
223 const struct nphy_rf_control_override_rev2
*rf_ctrl
;
225 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
, ~(field
));
228 b43_phy_set(dev
, B43_NPHY_RFCTL_OVER
, field
);
231 for (i
= 0; i
< 2; i
++) {
232 if (index
<= 1 || index
== 16) {
234 "Unsupported RF Ctrl Override call\n");
238 if (index
== 2 || index
== 10 ||
239 (index
>= 13 && index
<= 15)) {
243 rf_ctrl
= &tbl_rf_control_override_rev2
[index
- 2];
244 addr
= B43_PHY_N((i
== 0) ?
245 rf_ctrl
->addr0
: rf_ctrl
->addr1
);
248 b43_phy_maskset(dev
, addr
, ~(rf_ctrl
->bmask
),
249 (value
<< rf_ctrl
->shift
));
251 b43_phy_set(dev
, B43_NPHY_RFCTL_OVER
, 0x1);
252 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
253 B43_NPHY_RFCTL_CMD_START
);
255 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
, 0xFFFE);
260 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlIntcOverride */
261 static void b43_nphy_rf_ctl_intc_override(struct b43_wldev
*dev
,
262 enum n_intc_override intc_override
,
268 B43_WARN_ON(dev
->phy
.rev
< 3);
270 for (i
= 0; i
< 2; i
++) {
271 if ((core
== 1 && i
== 1) || (core
== 2 && !i
))
275 B43_NPHY_RFCTL_INTC1
: B43_NPHY_RFCTL_INTC2
;
276 b43_phy_set(dev
, reg
, 0x400);
278 switch (intc_override
) {
279 case N_INTC_OVERRIDE_OFF
:
280 b43_phy_write(dev
, reg
, 0);
281 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
283 case N_INTC_OVERRIDE_TRSW
:
285 b43_phy_maskset(dev
, B43_NPHY_RFCTL_INTC1
,
286 0xFC3F, (value
<< 6));
287 b43_phy_maskset(dev
, B43_NPHY_TXF_40CO_B1S1
,
289 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
290 B43_NPHY_RFCTL_CMD_START
);
291 for (j
= 0; j
< 100; j
++) {
292 if (!(b43_phy_read(dev
, B43_NPHY_RFCTL_CMD
) & B43_NPHY_RFCTL_CMD_START
)) {
300 "intc override timeout\n");
301 b43_phy_mask(dev
, B43_NPHY_TXF_40CO_B1S1
,
304 b43_phy_maskset(dev
, B43_NPHY_RFCTL_INTC2
,
305 0xFC3F, (value
<< 6));
306 b43_phy_maskset(dev
, B43_NPHY_RFCTL_OVER
,
308 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
309 B43_NPHY_RFCTL_CMD_RXTX
);
310 for (j
= 0; j
< 100; j
++) {
311 if (!(b43_phy_read(dev
, B43_NPHY_RFCTL_CMD
) & B43_NPHY_RFCTL_CMD_RXTX
)) {
319 "intc override timeout\n");
320 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
,
324 case N_INTC_OVERRIDE_PA
:
325 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
332 b43_phy_maskset(dev
, reg
, ~tmp
, val
);
334 case N_INTC_OVERRIDE_EXT_LNA_PU
:
335 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
342 b43_phy_maskset(dev
, reg
, ~tmp
, val
);
344 case N_INTC_OVERRIDE_EXT_LNA_GAIN
:
345 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
352 b43_phy_maskset(dev
, reg
, ~tmp
, val
);
358 /**************************************************
360 **************************************************/
362 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/clip-detection */
363 static void b43_nphy_write_clip_detection(struct b43_wldev
*dev
,
366 b43_phy_write(dev
, B43_NPHY_C1_CLIP1THRES
, clip_st
[0]);
367 b43_phy_write(dev
, B43_NPHY_C2_CLIP1THRES
, clip_st
[1]);
370 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/clip-detection */
371 static void b43_nphy_read_clip_detection(struct b43_wldev
*dev
, u16
*clip_st
)
373 clip_st
[0] = b43_phy_read(dev
, B43_NPHY_C1_CLIP1THRES
);
374 clip_st
[1] = b43_phy_read(dev
, B43_NPHY_C2_CLIP1THRES
);
377 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/classifier */
378 static u16
b43_nphy_classifier(struct b43_wldev
*dev
, u16 mask
, u16 val
)
382 if (dev
->dev
->core_rev
== 16)
383 b43_mac_suspend(dev
);
385 tmp
= b43_phy_read(dev
, B43_NPHY_CLASSCTL
);
386 tmp
&= (B43_NPHY_CLASSCTL_CCKEN
| B43_NPHY_CLASSCTL_OFDMEN
|
387 B43_NPHY_CLASSCTL_WAITEDEN
);
390 b43_phy_maskset(dev
, B43_NPHY_CLASSCTL
, 0xFFF8, tmp
);
392 if (dev
->dev
->core_rev
== 16)
398 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CCA */
399 static void b43_nphy_reset_cca(struct b43_wldev
*dev
)
403 b43_phy_force_clock(dev
, 1);
404 bbcfg
= b43_phy_read(dev
, B43_NPHY_BBCFG
);
405 b43_phy_write(dev
, B43_NPHY_BBCFG
, bbcfg
| B43_NPHY_BBCFG_RSTCCA
);
407 b43_phy_write(dev
, B43_NPHY_BBCFG
, bbcfg
& ~B43_NPHY_BBCFG_RSTCCA
);
408 b43_phy_force_clock(dev
, 0);
409 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
412 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/carriersearch */
413 static void b43_nphy_stay_in_carrier_search(struct b43_wldev
*dev
, bool enable
)
415 struct b43_phy
*phy
= &dev
->phy
;
416 struct b43_phy_n
*nphy
= phy
->n
;
419 static const u16 clip
[] = { 0xFFFF, 0xFFFF };
420 if (nphy
->deaf_count
++ == 0) {
421 nphy
->classifier_state
= b43_nphy_classifier(dev
, 0, 0);
422 b43_nphy_classifier(dev
, 0x7, 0);
423 b43_nphy_read_clip_detection(dev
, nphy
->clip_state
);
424 b43_nphy_write_clip_detection(dev
, clip
);
426 b43_nphy_reset_cca(dev
);
428 if (--nphy
->deaf_count
== 0) {
429 b43_nphy_classifier(dev
, 0x7, nphy
->classifier_state
);
430 b43_nphy_write_clip_detection(dev
, nphy
->clip_state
);
435 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/AdjustLnaGainTbl */
436 static void b43_nphy_adjust_lna_gain_table(struct b43_wldev
*dev
)
438 struct b43_phy_n
*nphy
= dev
->phy
.n
;
445 static const u16 lna_gain
[4] = { -2, 10, 19, 25 };
447 if (nphy
->hang_avoid
)
448 b43_nphy_stay_in_carrier_search(dev
, 1);
450 if (nphy
->gain_boost
) {
451 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
455 tmp
= 40370 - 315 * dev
->phy
.channel
;
456 gain
[0] = ((tmp
>> 13) + ((tmp
>> 12) & 1));
457 tmp
= 23242 - 224 * dev
->phy
.channel
;
458 gain
[1] = ((tmp
>> 13) + ((tmp
>> 12) & 1));
465 for (i
= 0; i
< 2; i
++) {
466 if (nphy
->elna_gain_config
) {
467 data
[0] = 19 + gain
[i
];
468 data
[1] = 25 + gain
[i
];
469 data
[2] = 25 + gain
[i
];
470 data
[3] = 25 + gain
[i
];
472 data
[0] = lna_gain
[0] + gain
[i
];
473 data
[1] = lna_gain
[1] + gain
[i
];
474 data
[2] = lna_gain
[2] + gain
[i
];
475 data
[3] = lna_gain
[3] + gain
[i
];
477 b43_ntab_write_bulk(dev
, B43_NTAB16(i
, 8), 4, data
);
479 minmax
[i
] = 23 + gain
[i
];
482 b43_phy_maskset(dev
, B43_NPHY_C1_MINMAX_GAIN
, ~B43_NPHY_C1_MINGAIN
,
483 minmax
[0] << B43_NPHY_C1_MINGAIN_SHIFT
);
484 b43_phy_maskset(dev
, B43_NPHY_C2_MINMAX_GAIN
, ~B43_NPHY_C2_MINGAIN
,
485 minmax
[1] << B43_NPHY_C2_MINGAIN_SHIFT
);
487 if (nphy
->hang_avoid
)
488 b43_nphy_stay_in_carrier_search(dev
, 0);
491 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetRfSeq */
492 static void b43_nphy_set_rf_sequence(struct b43_wldev
*dev
, u8 cmd
,
493 u8
*events
, u8
*delays
, u8 length
)
495 struct b43_phy_n
*nphy
= dev
->phy
.n
;
497 u8 end
= (dev
->phy
.rev
>= 3) ? 0x1F : 0x0F;
498 u16 offset1
= cmd
<< 4;
499 u16 offset2
= offset1
+ 0x80;
501 if (nphy
->hang_avoid
)
502 b43_nphy_stay_in_carrier_search(dev
, true);
504 b43_ntab_write_bulk(dev
, B43_NTAB8(7, offset1
), length
, events
);
505 b43_ntab_write_bulk(dev
, B43_NTAB8(7, offset2
), length
, delays
);
507 for (i
= length
; i
< 16; i
++) {
508 b43_ntab_write(dev
, B43_NTAB8(7, offset1
+ i
), end
);
509 b43_ntab_write(dev
, B43_NTAB8(7, offset2
+ i
), 1);
512 if (nphy
->hang_avoid
)
513 b43_nphy_stay_in_carrier_search(dev
, false);
516 /**************************************************
518 **************************************************/
520 /* http://bcm-v4.sipsolutions.net/PHY/radio2057_rcal */
521 static u8
b43_radio_2057_rcal(struct b43_wldev
*dev
)
523 struct b43_phy
*phy
= &dev
->phy
;
526 if (phy
->radio_rev
== 5) {
527 b43_phy_mask(dev
, 0x342, ~0x2);
529 b43_radio_set(dev
, R2057_IQTEST_SEL_PU
, 0x1);
530 b43_radio_maskset(dev
, 0x1ca, ~0x2, 0x1);
533 b43_radio_set(dev
, R2057_RCAL_CONFIG
, 0x1);
535 b43_radio_set(dev
, R2057_RCAL_CONFIG
, 0x3);
536 if (!b43_radio_wait_value(dev
, R2057_RCCAL_N1_1
, 1, 1, 100, 1000000)) {
537 b43err(dev
->wl
, "Radio 0x2057 rcal timeout\n");
540 b43_radio_mask(dev
, R2057_RCAL_CONFIG
, ~0x2);
541 tmp
= b43_radio_read(dev
, R2057_RCAL_STATUS
) & 0x3E;
542 b43_radio_mask(dev
, R2057_RCAL_CONFIG
, ~0x1);
544 if (phy
->radio_rev
== 5) {
545 b43_radio_mask(dev
, R2057_IPA2G_CASCONV_CORE0
, ~0x1);
546 b43_radio_mask(dev
, 0x1ca, ~0x2);
548 if (phy
->radio_rev
<= 4 || phy
->radio_rev
== 6) {
549 b43_radio_maskset(dev
, R2057_TEMPSENSE_CONFIG
, ~0x3C, tmp
);
550 b43_radio_maskset(dev
, R2057_BANDGAP_RCAL_TRIM
, ~0xF0,
557 /* http://bcm-v4.sipsolutions.net/PHY/radio2057_rccal */
558 static u16
b43_radio_2057_rccal(struct b43_wldev
*dev
)
560 struct b43_phy
*phy
= &dev
->phy
;
561 bool special
= (phy
->radio_rev
== 3 || phy
->radio_rev
== 4 ||
562 phy
->radio_rev
== 6);
566 b43_radio_write(dev
, R2057_RCCAL_MASTER
, 0x61);
567 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0xC0);
569 b43_radio_write(dev
, 0x1AE, 0x61);
570 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0xE1);
572 b43_radio_write(dev
, R2057_RCCAL_X1
, 0x6E);
573 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x55);
574 if (!b43_radio_wait_value(dev
, R2057_RCCAL_DONE_OSCCAP
, 1, 1, 500,
576 b43dbg(dev
->wl
, "Radio 0x2057 rccal timeout\n");
577 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x15);
579 b43_radio_write(dev
, R2057_RCCAL_MASTER
, 0x69);
580 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0xB0);
582 b43_radio_write(dev
, 0x1AE, 0x69);
583 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0xD5);
585 b43_radio_write(dev
, R2057_RCCAL_X1
, 0x6E);
586 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x55);
587 if (!b43_radio_wait_value(dev
, R2057_RCCAL_DONE_OSCCAP
, 1, 1, 500,
589 b43dbg(dev
->wl
, "Radio 0x2057 rccal timeout\n");
590 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x15);
592 b43_radio_write(dev
, R2057_RCCAL_MASTER
, 0x73);
593 b43_radio_write(dev
, R2057_RCCAL_X1
, 0x28);
594 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0xB0);
596 b43_radio_write(dev
, 0x1AE, 0x73);
597 b43_radio_write(dev
, R2057_RCCAL_X1
, 0x6E);
598 b43_radio_write(dev
, R2057_RCCAL_TRC0
, 0x99);
600 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x55);
601 if (!b43_radio_wait_value(dev
, R2057_RCCAL_DONE_OSCCAP
, 1, 1, 500,
603 b43err(dev
->wl
, "Radio 0x2057 rcal timeout\n");
606 tmp
= b43_radio_read(dev
, R2057_RCCAL_DONE_OSCCAP
);
607 b43_radio_write(dev
, R2057_RCCAL_START_R1_Q1_P1
, 0x15);
611 static void b43_radio_2057_init_pre(struct b43_wldev
*dev
)
613 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
, ~B43_NPHY_RFCTL_CMD_CHIP0PU
);
614 /* Maybe wl meant to reset and set (order?) RFCTL_CMD_OEPORFORCE? */
615 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
, B43_NPHY_RFCTL_CMD_OEPORFORCE
);
616 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
, ~B43_NPHY_RFCTL_CMD_OEPORFORCE
);
617 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
, B43_NPHY_RFCTL_CMD_CHIP0PU
);
620 static void b43_radio_2057_init_post(struct b43_wldev
*dev
)
622 b43_radio_set(dev
, R2057_XTALPUOVR_PINCTRL
, 0x1);
624 b43_radio_set(dev
, R2057_RFPLL_MISC_CAL_RESETN
, 0x78);
625 b43_radio_set(dev
, R2057_XTAL_CONFIG2
, 0x80);
627 b43_radio_mask(dev
, R2057_RFPLL_MISC_CAL_RESETN
, ~0x78);
628 b43_radio_mask(dev
, R2057_XTAL_CONFIG2
, ~0x80);
630 if (dev
->phy
.n
->init_por
) {
631 b43_radio_2057_rcal(dev
);
632 b43_radio_2057_rccal(dev
);
634 b43_radio_mask(dev
, R2057_RFPLL_MASTER
, ~0x8);
636 dev
->phy
.n
->init_por
= false;
639 /* http://bcm-v4.sipsolutions.net/802.11/Radio/2057/Init */
640 static void b43_radio_2057_init(struct b43_wldev
*dev
)
642 b43_radio_2057_init_pre(dev
);
643 r2057_upload_inittabs(dev
);
644 b43_radio_2057_init_post(dev
);
647 /**************************************************
649 **************************************************/
651 static void b43_chantab_radio_2056_upload(struct b43_wldev
*dev
,
652 const struct b43_nphy_channeltab_entry_rev3
*e
)
654 b43_radio_write(dev
, B2056_SYN_PLL_VCOCAL1
, e
->radio_syn_pll_vcocal1
);
655 b43_radio_write(dev
, B2056_SYN_PLL_VCOCAL2
, e
->radio_syn_pll_vcocal2
);
656 b43_radio_write(dev
, B2056_SYN_PLL_REFDIV
, e
->radio_syn_pll_refdiv
);
657 b43_radio_write(dev
, B2056_SYN_PLL_MMD2
, e
->radio_syn_pll_mmd2
);
658 b43_radio_write(dev
, B2056_SYN_PLL_MMD1
, e
->radio_syn_pll_mmd1
);
659 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER1
,
660 e
->radio_syn_pll_loopfilter1
);
661 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER2
,
662 e
->radio_syn_pll_loopfilter2
);
663 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER3
,
664 e
->radio_syn_pll_loopfilter3
);
665 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER4
,
666 e
->radio_syn_pll_loopfilter4
);
667 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER5
,
668 e
->radio_syn_pll_loopfilter5
);
669 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR27
,
670 e
->radio_syn_reserved_addr27
);
671 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR28
,
672 e
->radio_syn_reserved_addr28
);
673 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR29
,
674 e
->radio_syn_reserved_addr29
);
675 b43_radio_write(dev
, B2056_SYN_LOGEN_VCOBUF1
,
676 e
->radio_syn_logen_vcobuf1
);
677 b43_radio_write(dev
, B2056_SYN_LOGEN_MIXER2
, e
->radio_syn_logen_mixer2
);
678 b43_radio_write(dev
, B2056_SYN_LOGEN_BUF3
, e
->radio_syn_logen_buf3
);
679 b43_radio_write(dev
, B2056_SYN_LOGEN_BUF4
, e
->radio_syn_logen_buf4
);
681 b43_radio_write(dev
, B2056_RX0
| B2056_RX_LNAA_TUNE
,
682 e
->radio_rx0_lnaa_tune
);
683 b43_radio_write(dev
, B2056_RX0
| B2056_RX_LNAG_TUNE
,
684 e
->radio_rx0_lnag_tune
);
686 b43_radio_write(dev
, B2056_TX0
| B2056_TX_INTPAA_BOOST_TUNE
,
687 e
->radio_tx0_intpaa_boost_tune
);
688 b43_radio_write(dev
, B2056_TX0
| B2056_TX_INTPAG_BOOST_TUNE
,
689 e
->radio_tx0_intpag_boost_tune
);
690 b43_radio_write(dev
, B2056_TX0
| B2056_TX_PADA_BOOST_TUNE
,
691 e
->radio_tx0_pada_boost_tune
);
692 b43_radio_write(dev
, B2056_TX0
| B2056_TX_PADG_BOOST_TUNE
,
693 e
->radio_tx0_padg_boost_tune
);
694 b43_radio_write(dev
, B2056_TX0
| B2056_TX_PGAA_BOOST_TUNE
,
695 e
->radio_tx0_pgaa_boost_tune
);
696 b43_radio_write(dev
, B2056_TX0
| B2056_TX_PGAG_BOOST_TUNE
,
697 e
->radio_tx0_pgag_boost_tune
);
698 b43_radio_write(dev
, B2056_TX0
| B2056_TX_MIXA_BOOST_TUNE
,
699 e
->radio_tx0_mixa_boost_tune
);
700 b43_radio_write(dev
, B2056_TX0
| B2056_TX_MIXG_BOOST_TUNE
,
701 e
->radio_tx0_mixg_boost_tune
);
703 b43_radio_write(dev
, B2056_RX1
| B2056_RX_LNAA_TUNE
,
704 e
->radio_rx1_lnaa_tune
);
705 b43_radio_write(dev
, B2056_RX1
| B2056_RX_LNAG_TUNE
,
706 e
->radio_rx1_lnag_tune
);
708 b43_radio_write(dev
, B2056_TX1
| B2056_TX_INTPAA_BOOST_TUNE
,
709 e
->radio_tx1_intpaa_boost_tune
);
710 b43_radio_write(dev
, B2056_TX1
| B2056_TX_INTPAG_BOOST_TUNE
,
711 e
->radio_tx1_intpag_boost_tune
);
712 b43_radio_write(dev
, B2056_TX1
| B2056_TX_PADA_BOOST_TUNE
,
713 e
->radio_tx1_pada_boost_tune
);
714 b43_radio_write(dev
, B2056_TX1
| B2056_TX_PADG_BOOST_TUNE
,
715 e
->radio_tx1_padg_boost_tune
);
716 b43_radio_write(dev
, B2056_TX1
| B2056_TX_PGAA_BOOST_TUNE
,
717 e
->radio_tx1_pgaa_boost_tune
);
718 b43_radio_write(dev
, B2056_TX1
| B2056_TX_PGAG_BOOST_TUNE
,
719 e
->radio_tx1_pgag_boost_tune
);
720 b43_radio_write(dev
, B2056_TX1
| B2056_TX_MIXA_BOOST_TUNE
,
721 e
->radio_tx1_mixa_boost_tune
);
722 b43_radio_write(dev
, B2056_TX1
| B2056_TX_MIXG_BOOST_TUNE
,
723 e
->radio_tx1_mixg_boost_tune
);
726 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Radio/2056Setup */
727 static void b43_radio_2056_setup(struct b43_wldev
*dev
,
728 const struct b43_nphy_channeltab_entry_rev3
*e
)
730 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
731 enum ieee80211_band band
= b43_current_band(dev
->wl
);
735 u16 pag_boost
, padg_boost
, pgag_boost
, mixg_boost
;
736 u16 paa_boost
, pada_boost
, pgaa_boost
, mixa_boost
;
738 B43_WARN_ON(dev
->phy
.rev
< 3);
740 b43_chantab_radio_2056_upload(dev
, e
);
741 b2056_upload_syn_pll_cp2(dev
, band
== IEEE80211_BAND_5GHZ
);
743 if (sprom
->boardflags2_lo
& B43_BFL2_GPLL_WAR
&&
744 b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
745 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER1
, 0x1F);
746 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER2
, 0x1F);
747 if (dev
->dev
->chip_id
== 0x4716) {
748 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER4
, 0x14);
749 b43_radio_write(dev
, B2056_SYN_PLL_CP2
, 0);
751 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER4
, 0x0B);
752 b43_radio_write(dev
, B2056_SYN_PLL_CP2
, 0x14);
755 if (sprom
->boardflags2_lo
& B43_BFL2_APLL_WAR
&&
756 b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
757 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER1
, 0x1F);
758 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER2
, 0x1F);
759 b43_radio_write(dev
, B2056_SYN_PLL_LOOPFILTER4
, 0x05);
760 b43_radio_write(dev
, B2056_SYN_PLL_CP2
, 0x0C);
763 if (dev
->phy
.n
->ipa2g_on
&& band
== IEEE80211_BAND_2GHZ
) {
764 for (i
= 0; i
< 2; i
++) {
765 offset
= i
? B2056_TX1
: B2056_TX0
;
766 if (dev
->phy
.rev
>= 5) {
768 offset
| B2056_TX_PADG_IDAC
, 0xcc);
770 if (dev
->dev
->chip_id
== 0x4716) {
786 offset
| B2056_TX_INTPAG_IMAIN_STAT
,
789 offset
| B2056_TX_INTPAG_IAUX_STAT
,
792 offset
| B2056_TX_INTPAG_CASCBIAS
,
795 offset
| B2056_TX_INTPAG_BOOST_TUNE
,
798 offset
| B2056_TX_PGAG_BOOST_TUNE
,
801 offset
| B2056_TX_PADG_BOOST_TUNE
,
804 offset
| B2056_TX_MIXG_BOOST_TUNE
,
807 bias
= dev
->phy
.is_40mhz
? 0x40 : 0x20;
809 offset
| B2056_TX_INTPAG_IMAIN_STAT
,
812 offset
| B2056_TX_INTPAG_IAUX_STAT
,
815 offset
| B2056_TX_INTPAG_CASCBIAS
,
818 b43_radio_write(dev
, offset
| B2056_TX_PA_SPARE1
, 0xee);
820 } else if (dev
->phy
.n
->ipa5g_on
&& band
== IEEE80211_BAND_5GHZ
) {
821 u16 freq
= dev
->phy
.channel_freq
;
827 } else if (freq
< 5340) {
832 } else if (freq
< 5650) {
841 pgaa_boost
= -(freq
- 18) / 36 + 168;
847 for (i
= 0; i
< 2; i
++) {
848 offset
= i
? B2056_TX1
: B2056_TX0
;
851 offset
| B2056_TX_INTPAA_BOOST_TUNE
, paa_boost
);
853 offset
| B2056_TX_PADA_BOOST_TUNE
, pada_boost
);
855 offset
| B2056_TX_PGAA_BOOST_TUNE
, pgaa_boost
);
857 offset
| B2056_TX_MIXA_BOOST_TUNE
, mixa_boost
);
859 offset
| B2056_TX_TXSPARE1
, 0x30);
861 offset
| B2056_TX_PA_SPARE2
, 0xee);
863 offset
| B2056_TX_PADA_CASCBIAS
, 0x03);
865 offset
| B2056_TX_INTPAA_IAUX_STAT
, 0x50);
867 offset
| B2056_TX_INTPAA_IMAIN_STAT
, 0x50);
869 offset
| B2056_TX_INTPAA_CASCBIAS
, 0x30);
874 /* VCO calibration */
875 b43_radio_write(dev
, B2056_SYN_PLL_VCOCAL12
, 0x00);
876 b43_radio_write(dev
, B2056_TX_INTPAA_PA_MISC
, 0x38);
877 b43_radio_write(dev
, B2056_TX_INTPAA_PA_MISC
, 0x18);
878 b43_radio_write(dev
, B2056_TX_INTPAA_PA_MISC
, 0x38);
879 b43_radio_write(dev
, B2056_TX_INTPAA_PA_MISC
, 0x39);
883 static u8
b43_radio_2056_rcal(struct b43_wldev
*dev
)
885 struct b43_phy
*phy
= &dev
->phy
;
891 mast2
= b43_radio_read(dev
, B2056_SYN_PLL_MAST2
);
892 b43_radio_write(dev
, B2056_SYN_PLL_MAST2
, mast2
| 0x7);
895 b43_radio_write(dev
, B2056_SYN_RCAL_MASTER
, 0x01);
897 b43_radio_write(dev
, B2056_SYN_RCAL_MASTER
, 0x09);
899 if (!b43_radio_wait_value(dev
, B2056_SYN_RCAL_CODE_OUT
, 0x80, 0x80, 100,
901 b43err(dev
->wl
, "Radio recalibration timeout\n");
905 b43_radio_write(dev
, B2056_SYN_RCAL_MASTER
, 0x01);
906 tmp
= b43_radio_read(dev
, B2056_SYN_RCAL_CODE_OUT
);
907 b43_radio_write(dev
, B2056_SYN_RCAL_MASTER
, 0x00);
909 b43_radio_write(dev
, B2056_SYN_PLL_MAST2
, mast2
);
914 static void b43_radio_init2056_pre(struct b43_wldev
*dev
)
916 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
917 ~B43_NPHY_RFCTL_CMD_CHIP0PU
);
918 /* Maybe wl meant to reset and set (order?) RFCTL_CMD_OEPORFORCE? */
919 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
920 B43_NPHY_RFCTL_CMD_OEPORFORCE
);
921 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
922 ~B43_NPHY_RFCTL_CMD_OEPORFORCE
);
923 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
924 B43_NPHY_RFCTL_CMD_CHIP0PU
);
927 static void b43_radio_init2056_post(struct b43_wldev
*dev
)
929 b43_radio_set(dev
, B2056_SYN_COM_CTRL
, 0xB);
930 b43_radio_set(dev
, B2056_SYN_COM_PU
, 0x2);
931 b43_radio_set(dev
, B2056_SYN_COM_RESET
, 0x2);
933 b43_radio_mask(dev
, B2056_SYN_COM_RESET
, ~0x2);
934 b43_radio_mask(dev
, B2056_SYN_PLL_MAST2
, ~0xFC);
935 b43_radio_mask(dev
, B2056_SYN_RCCAL_CTRL0
, ~0x1);
936 if (dev
->phy
.n
->init_por
)
937 b43_radio_2056_rcal(dev
);
941 * Initialize a Broadcom 2056 N-radio
942 * http://bcm-v4.sipsolutions.net/802.11/Radio/2056/Init
944 static void b43_radio_init2056(struct b43_wldev
*dev
)
946 b43_radio_init2056_pre(dev
);
947 b2056_upload_inittabs(dev
, 0, 0);
948 b43_radio_init2056_post(dev
);
950 dev
->phy
.n
->init_por
= false;
953 /**************************************************
955 **************************************************/
957 static void b43_chantab_radio_upload(struct b43_wldev
*dev
,
958 const struct b43_nphy_channeltab_entry_rev2
*e
)
960 b43_radio_write(dev
, B2055_PLL_REF
, e
->radio_pll_ref
);
961 b43_radio_write(dev
, B2055_RF_PLLMOD0
, e
->radio_rf_pllmod0
);
962 b43_radio_write(dev
, B2055_RF_PLLMOD1
, e
->radio_rf_pllmod1
);
963 b43_radio_write(dev
, B2055_VCO_CAPTAIL
, e
->radio_vco_captail
);
964 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
966 b43_radio_write(dev
, B2055_VCO_CAL1
, e
->radio_vco_cal1
);
967 b43_radio_write(dev
, B2055_VCO_CAL2
, e
->radio_vco_cal2
);
968 b43_radio_write(dev
, B2055_PLL_LFC1
, e
->radio_pll_lfc1
);
969 b43_radio_write(dev
, B2055_PLL_LFR1
, e
->radio_pll_lfr1
);
970 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
972 b43_radio_write(dev
, B2055_PLL_LFC2
, e
->radio_pll_lfc2
);
973 b43_radio_write(dev
, B2055_LGBUF_CENBUF
, e
->radio_lgbuf_cenbuf
);
974 b43_radio_write(dev
, B2055_LGEN_TUNE1
, e
->radio_lgen_tune1
);
975 b43_radio_write(dev
, B2055_LGEN_TUNE2
, e
->radio_lgen_tune2
);
976 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
978 b43_radio_write(dev
, B2055_C1_LGBUF_ATUNE
, e
->radio_c1_lgbuf_atune
);
979 b43_radio_write(dev
, B2055_C1_LGBUF_GTUNE
, e
->radio_c1_lgbuf_gtune
);
980 b43_radio_write(dev
, B2055_C1_RX_RFR1
, e
->radio_c1_rx_rfr1
);
981 b43_radio_write(dev
, B2055_C1_TX_PGAPADTN
, e
->radio_c1_tx_pgapadtn
);
982 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
984 b43_radio_write(dev
, B2055_C1_TX_MXBGTRIM
, e
->radio_c1_tx_mxbgtrim
);
985 b43_radio_write(dev
, B2055_C2_LGBUF_ATUNE
, e
->radio_c2_lgbuf_atune
);
986 b43_radio_write(dev
, B2055_C2_LGBUF_GTUNE
, e
->radio_c2_lgbuf_gtune
);
987 b43_radio_write(dev
, B2055_C2_RX_RFR1
, e
->radio_c2_rx_rfr1
);
988 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
990 b43_radio_write(dev
, B2055_C2_TX_PGAPADTN
, e
->radio_c2_tx_pgapadtn
);
991 b43_radio_write(dev
, B2055_C2_TX_MXBGTRIM
, e
->radio_c2_tx_mxbgtrim
);
994 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Radio/2055Setup */
995 static void b43_radio_2055_setup(struct b43_wldev
*dev
,
996 const struct b43_nphy_channeltab_entry_rev2
*e
)
998 B43_WARN_ON(dev
->phy
.rev
>= 3);
1000 b43_chantab_radio_upload(dev
, e
);
1002 b43_radio_write(dev
, B2055_VCO_CAL10
, 0x05);
1003 b43_radio_write(dev
, B2055_VCO_CAL10
, 0x45);
1004 b43_read32(dev
, B43_MMIO_MACCTL
); /* flush writes */
1005 b43_radio_write(dev
, B2055_VCO_CAL10
, 0x65);
1009 static void b43_radio_init2055_pre(struct b43_wldev
*dev
)
1011 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
1012 ~B43_NPHY_RFCTL_CMD_PORFORCE
);
1013 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
1014 B43_NPHY_RFCTL_CMD_CHIP0PU
|
1015 B43_NPHY_RFCTL_CMD_OEPORFORCE
);
1016 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
1017 B43_NPHY_RFCTL_CMD_PORFORCE
);
1020 static void b43_radio_init2055_post(struct b43_wldev
*dev
)
1022 struct b43_phy_n
*nphy
= dev
->phy
.n
;
1023 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
1024 bool workaround
= false;
1026 if (sprom
->revision
< 4)
1027 workaround
= (dev
->dev
->board_vendor
!= PCI_VENDOR_ID_BROADCOM
1028 && dev
->dev
->board_type
== SSB_BOARD_CB2_4321
1029 && dev
->dev
->board_rev
>= 0x41);
1032 !(sprom
->boardflags2_lo
& B43_BFL2_RXBB_INT_REG_DIS
);
1034 b43_radio_mask(dev
, B2055_MASTER1
, 0xFFF3);
1036 b43_radio_mask(dev
, B2055_C1_RX_BB_REG
, 0x7F);
1037 b43_radio_mask(dev
, B2055_C2_RX_BB_REG
, 0x7F);
1039 b43_radio_maskset(dev
, B2055_RRCCAL_NOPTSEL
, 0xFFC0, 0x2C);
1040 b43_radio_write(dev
, B2055_CAL_MISC
, 0x3C);
1041 b43_radio_mask(dev
, B2055_CAL_MISC
, 0xFFBE);
1042 b43_radio_set(dev
, B2055_CAL_LPOCTL
, 0x80);
1043 b43_radio_set(dev
, B2055_CAL_MISC
, 0x1);
1045 b43_radio_set(dev
, B2055_CAL_MISC
, 0x40);
1046 if (!b43_radio_wait_value(dev
, B2055_CAL_COUT2
, 0x80, 0x80, 10, 2000))
1047 b43err(dev
->wl
, "radio post init timeout\n");
1048 b43_radio_mask(dev
, B2055_CAL_LPOCTL
, 0xFF7F);
1049 b43_switch_channel(dev
, dev
->phy
.channel
);
1050 b43_radio_write(dev
, B2055_C1_RX_BB_LPF
, 0x9);
1051 b43_radio_write(dev
, B2055_C2_RX_BB_LPF
, 0x9);
1052 b43_radio_write(dev
, B2055_C1_RX_BB_MIDACHP
, 0x83);
1053 b43_radio_write(dev
, B2055_C2_RX_BB_MIDACHP
, 0x83);
1054 b43_radio_maskset(dev
, B2055_C1_LNA_GAINBST
, 0xFFF8, 0x6);
1055 b43_radio_maskset(dev
, B2055_C2_LNA_GAINBST
, 0xFFF8, 0x6);
1056 if (!nphy
->gain_boost
) {
1057 b43_radio_set(dev
, B2055_C1_RX_RFSPC1
, 0x2);
1058 b43_radio_set(dev
, B2055_C2_RX_RFSPC1
, 0x2);
1060 b43_radio_mask(dev
, B2055_C1_RX_RFSPC1
, 0xFFFD);
1061 b43_radio_mask(dev
, B2055_C2_RX_RFSPC1
, 0xFFFD);
1067 * Initialize a Broadcom 2055 N-radio
1068 * http://bcm-v4.sipsolutions.net/802.11/Radio/2055/Init
1070 static void b43_radio_init2055(struct b43_wldev
*dev
)
1072 b43_radio_init2055_pre(dev
);
1073 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
1074 /* Follow wl, not specs. Do not force uploading all regs */
1075 b2055_upload_inittab(dev
, 0, 0);
1077 bool ghz5
= b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
;
1078 b2055_upload_inittab(dev
, ghz5
, 0);
1080 b43_radio_init2055_post(dev
);
1083 /**************************************************
1085 **************************************************/
1087 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/LoadSampleTable */
1088 static int b43_nphy_load_samples(struct b43_wldev
*dev
,
1089 struct b43_c32
*samples
, u16 len
) {
1090 struct b43_phy_n
*nphy
= dev
->phy
.n
;
1094 data
= kzalloc(len
* sizeof(u32
), GFP_KERNEL
);
1096 b43err(dev
->wl
, "allocation for samples loading failed\n");
1099 if (nphy
->hang_avoid
)
1100 b43_nphy_stay_in_carrier_search(dev
, 1);
1102 for (i
= 0; i
< len
; i
++) {
1103 data
[i
] = (samples
[i
].i
& 0x3FF << 10);
1104 data
[i
] |= samples
[i
].q
& 0x3FF;
1106 b43_ntab_write_bulk(dev
, B43_NTAB32(17, 0), len
, data
);
1109 if (nphy
->hang_avoid
)
1110 b43_nphy_stay_in_carrier_search(dev
, 0);
1114 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GenLoadSamples */
1115 static u16
b43_nphy_gen_load_samples(struct b43_wldev
*dev
, u32 freq
, u16 max
,
1119 u16 bw
, len
, rot
, angle
;
1120 struct b43_c32
*samples
;
1123 bw
= (dev
->phy
.is_40mhz
) ? 40 : 20;
1127 if (b43_phy_read(dev
, B43_NPHY_BBCFG
) & B43_NPHY_BBCFG_RSTRX
)
1132 if (dev
->phy
.is_40mhz
)
1138 samples
= kcalloc(len
, sizeof(struct b43_c32
), GFP_KERNEL
);
1140 b43err(dev
->wl
, "allocation for samples generation failed\n");
1143 rot
= (((freq
* 36) / bw
) << 16) / 100;
1146 for (i
= 0; i
< len
; i
++) {
1147 samples
[i
] = b43_cordic(angle
);
1149 samples
[i
].q
= CORDIC_CONVERT(samples
[i
].q
* max
);
1150 samples
[i
].i
= CORDIC_CONVERT(samples
[i
].i
* max
);
1153 i
= b43_nphy_load_samples(dev
, samples
, len
);
1155 return (i
< 0) ? 0 : len
;
1158 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RunSamples */
1159 static void b43_nphy_run_samples(struct b43_wldev
*dev
, u16 samps
, u16 loops
,
1160 u16 wait
, bool iqmode
, bool dac_test
)
1162 struct b43_phy_n
*nphy
= dev
->phy
.n
;
1167 if (nphy
->hang_avoid
)
1168 b43_nphy_stay_in_carrier_search(dev
, true);
1170 if ((nphy
->bb_mult_save
& 0x80000000) == 0) {
1171 tmp
= b43_ntab_read(dev
, B43_NTAB16(15, 87));
1172 nphy
->bb_mult_save
= (tmp
& 0xFFFF) | 0x80000000;
1175 if (!dev
->phy
.is_40mhz
)
1179 b43_ntab_write(dev
, B43_NTAB16(15, 87), tmp
);
1181 if (nphy
->hang_avoid
)
1182 b43_nphy_stay_in_carrier_search(dev
, false);
1184 b43_phy_write(dev
, B43_NPHY_SAMP_DEPCNT
, (samps
- 1));
1186 if (loops
!= 0xFFFF)
1187 b43_phy_write(dev
, B43_NPHY_SAMP_LOOPCNT
, (loops
- 1));
1189 b43_phy_write(dev
, B43_NPHY_SAMP_LOOPCNT
, loops
);
1191 b43_phy_write(dev
, B43_NPHY_SAMP_WAITCNT
, wait
);
1193 seq_mode
= b43_phy_read(dev
, B43_NPHY_RFSEQMODE
);
1195 b43_phy_set(dev
, B43_NPHY_RFSEQMODE
, B43_NPHY_RFSEQMODE_CAOVER
);
1197 b43_phy_mask(dev
, B43_NPHY_IQLOCAL_CMDGCTL
, 0x7FFF);
1198 b43_phy_set(dev
, B43_NPHY_IQLOCAL_CMDGCTL
, 0x8000);
1201 b43_phy_write(dev
, B43_NPHY_SAMP_CMD
, 5);
1203 b43_phy_write(dev
, B43_NPHY_SAMP_CMD
, 1);
1205 for (i
= 0; i
< 100; i
++) {
1206 if (!(b43_phy_read(dev
, B43_NPHY_RFSEQST
) & 1)) {
1213 b43err(dev
->wl
, "run samples timeout\n");
1215 b43_phy_write(dev
, B43_NPHY_RFSEQMODE
, seq_mode
);
1218 /**************************************************
1220 **************************************************/
1222 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ScaleOffsetRssi */
1223 static void b43_nphy_scale_offset_rssi(struct b43_wldev
*dev
, u16 scale
,
1225 enum n_rail_type rail
,
1226 enum n_rssi_type rssi_type
)
1229 bool core1or5
= (core
== 1) || (core
== 5);
1230 bool core2or5
= (core
== 2) || (core
== 5);
1232 offset
= clamp_val(offset
, -32, 31);
1233 tmp
= ((scale
& 0x3F) << 8) | (offset
& 0x3F);
1235 switch (rssi_type
) {
1237 if (core1or5
&& rail
== N_RAIL_I
)
1238 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_Z
, tmp
);
1239 if (core1or5
&& rail
== N_RAIL_Q
)
1240 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Z
, tmp
);
1241 if (core2or5
&& rail
== N_RAIL_I
)
1242 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_Z
, tmp
);
1243 if (core2or5
&& rail
== N_RAIL_Q
)
1244 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Z
, tmp
);
1247 if (core1or5
&& rail
== N_RAIL_I
)
1248 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_X
, tmp
);
1249 if (core1or5
&& rail
== N_RAIL_Q
)
1250 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_X
, tmp
);
1251 if (core2or5
&& rail
== N_RAIL_I
)
1252 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_X
, tmp
);
1253 if (core2or5
&& rail
== N_RAIL_Q
)
1254 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_X
, tmp
);
1257 if (core1or5
&& rail
== N_RAIL_I
)
1258 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_Y
, tmp
);
1259 if (core1or5
&& rail
== N_RAIL_Q
)
1260 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Y
, tmp
);
1261 if (core2or5
&& rail
== N_RAIL_I
)
1262 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_Y
, tmp
);
1263 if (core2or5
&& rail
== N_RAIL_Q
)
1264 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Y
, tmp
);
1267 if (core1or5
&& rail
== N_RAIL_I
)
1268 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_TBD
, tmp
);
1269 if (core1or5
&& rail
== N_RAIL_Q
)
1270 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_TBD
, tmp
);
1271 if (core2or5
&& rail
== N_RAIL_I
)
1272 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_TBD
, tmp
);
1273 if (core2or5
&& rail
== N_RAIL_Q
)
1274 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_TBD
, tmp
);
1277 if (core1or5
&& rail
== N_RAIL_I
)
1278 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_PWRDET
, tmp
);
1279 if (core1or5
&& rail
== N_RAIL_Q
)
1280 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_PWRDET
, tmp
);
1281 if (core2or5
&& rail
== N_RAIL_I
)
1282 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_PWRDET
, tmp
);
1283 if (core2or5
&& rail
== N_RAIL_Q
)
1284 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_PWRDET
, tmp
);
1286 case N_RSSI_TSSI_2G
:
1288 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_TSSI
, tmp
);
1290 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_TSSI
, tmp
);
1292 case N_RSSI_TSSI_5G
:
1294 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_TSSI
, tmp
);
1296 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_TSSI
, tmp
);
1301 static void b43_nphy_rev3_rssi_select(struct b43_wldev
*dev
, u8 code
,
1302 enum n_rssi_type rssi_type
)
1308 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER1
, 0xFDFF);
1309 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER
, 0xFDFF);
1310 b43_phy_mask(dev
, B43_NPHY_AFECTL_C1
, 0xFCFF);
1311 b43_phy_mask(dev
, B43_NPHY_AFECTL_C2
, 0xFCFF);
1312 b43_phy_mask(dev
, B43_NPHY_TXF_40CO_B1S0
, 0xFFDF);
1313 b43_phy_mask(dev
, B43_NPHY_TXF_40CO_B32S1
, 0xFFDF);
1314 b43_phy_mask(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP1
, 0xFFC3);
1315 b43_phy_mask(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP2
, 0xFFC3);
1317 for (i
= 0; i
< 2; i
++) {
1318 if ((code
== 1 && i
== 1) || (code
== 2 && !i
))
1322 B43_NPHY_AFECTL_OVER1
: B43_NPHY_AFECTL_OVER
;
1323 b43_phy_maskset(dev
, reg
, 0xFDFF, 0x0200);
1325 if (rssi_type
== N_RSSI_W1
||
1326 rssi_type
== N_RSSI_W2
||
1327 rssi_type
== N_RSSI_NB
) {
1329 B43_NPHY_AFECTL_C1
:
1331 b43_phy_maskset(dev
, reg
, 0xFCFF, 0);
1334 B43_NPHY_RFCTL_LUT_TRSW_UP1
:
1335 B43_NPHY_RFCTL_LUT_TRSW_UP2
;
1336 b43_phy_maskset(dev
, reg
, 0xFFC3, 0);
1338 if (rssi_type
== N_RSSI_W1
)
1339 val
= (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) ? 4 : 8;
1340 else if (rssi_type
== N_RSSI_W2
)
1344 b43_phy_set(dev
, reg
, val
);
1347 B43_NPHY_TXF_40CO_B1S0
:
1348 B43_NPHY_TXF_40CO_B32S1
;
1349 b43_phy_set(dev
, reg
, 0x0020);
1351 if (rssi_type
== N_RSSI_TBD
)
1353 else if (rssi_type
== N_RSSI_IQ
)
1359 B43_NPHY_AFECTL_C1
:
1362 b43_phy_maskset(dev
, reg
, 0xFCFF, val
);
1363 b43_phy_maskset(dev
, reg
, 0xF3FF, val
<< 2);
1365 if (rssi_type
!= N_RSSI_IQ
&&
1366 rssi_type
!= N_RSSI_TBD
) {
1367 enum ieee80211_band band
=
1368 b43_current_band(dev
->wl
);
1370 if (b43_nphy_ipa(dev
))
1371 val
= (band
== IEEE80211_BAND_5GHZ
) ? 0xC : 0xE;
1374 reg
= (i
== 0) ? 0x2000 : 0x3000;
1375 reg
|= B2055_PADDRV
;
1376 b43_radio_write(dev
, reg
, val
);
1379 B43_NPHY_AFECTL_OVER1
:
1380 B43_NPHY_AFECTL_OVER
;
1381 b43_phy_set(dev
, reg
, 0x0200);
1388 static void b43_nphy_rev2_rssi_select(struct b43_wldev
*dev
, u8 code
,
1389 enum n_rssi_type rssi_type
)
1392 bool rssi_w1_w2_nb
= false;
1394 switch (rssi_type
) {
1399 rssi_w1_w2_nb
= true;
1411 val
= (val
<< 12) | (val
<< 14);
1412 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C1
, 0x0FFF, val
);
1413 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C2
, 0x0FFF, val
);
1415 if (rssi_w1_w2_nb
) {
1416 b43_phy_maskset(dev
, B43_NPHY_RFCTL_RSSIO1
, 0xFFCF,
1417 (rssi_type
+ 1) << 4);
1418 b43_phy_maskset(dev
, B43_NPHY_RFCTL_RSSIO2
, 0xFFCF,
1419 (rssi_type
+ 1) << 4);
1423 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER
, ~0x3000);
1424 if (rssi_w1_w2_nb
) {
1425 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
1426 ~(B43_NPHY_RFCTL_CMD_RXEN
|
1427 B43_NPHY_RFCTL_CMD_CORESEL
));
1428 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
,
1433 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
1434 ~B43_NPHY_RFCTL_CMD_START
);
1436 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
, ~0x1);
1439 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x3000);
1440 if (rssi_w1_w2_nb
) {
1441 b43_phy_maskset(dev
, B43_NPHY_RFCTL_CMD
,
1442 ~(B43_NPHY_RFCTL_CMD_RXEN
|
1443 B43_NPHY_RFCTL_CMD_CORESEL
),
1444 (B43_NPHY_RFCTL_CMD_RXEN
|
1445 code
<< B43_NPHY_RFCTL_CMD_CORESEL_SHIFT
));
1446 b43_phy_set(dev
, B43_NPHY_RFCTL_OVER
,
1451 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
,
1452 B43_NPHY_RFCTL_CMD_START
);
1454 b43_phy_mask(dev
, B43_NPHY_RFCTL_OVER
, ~0x1);
1459 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSISel */
1460 static void b43_nphy_rssi_select(struct b43_wldev
*dev
, u8 code
,
1461 enum n_rssi_type type
)
1463 if (dev
->phy
.rev
>= 3)
1464 b43_nphy_rev3_rssi_select(dev
, code
, type
);
1466 b43_nphy_rev2_rssi_select(dev
, code
, type
);
1469 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetRssi2055Vcm */
1470 static void b43_nphy_set_rssi_2055_vcm(struct b43_wldev
*dev
,
1471 enum n_rssi_type rssi_type
, u8
*buf
)
1474 for (i
= 0; i
< 2; i
++) {
1475 if (rssi_type
== N_RSSI_NB
) {
1477 b43_radio_maskset(dev
, B2055_C1_B0NB_RSSIVCM
,
1479 b43_radio_maskset(dev
, B2055_C1_RX_BB_RSSICTL5
,
1482 b43_radio_maskset(dev
, B2055_C2_B0NB_RSSIVCM
,
1484 b43_radio_maskset(dev
, B2055_C2_RX_BB_RSSICTL5
,
1485 0xFC, buf
[2 * i
+ 1]);
1489 b43_radio_maskset(dev
, B2055_C1_RX_BB_RSSICTL5
,
1492 b43_radio_maskset(dev
, B2055_C2_RX_BB_RSSICTL5
,
1493 0xF3, buf
[2 * i
+ 1] << 2);
1498 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/PollRssi */
1499 static int b43_nphy_poll_rssi(struct b43_wldev
*dev
, enum n_rssi_type rssi_type
,
1504 u16 save_regs_phy
[9];
1507 if (dev
->phy
.rev
>= 3) {
1508 save_regs_phy
[0] = b43_phy_read(dev
, B43_NPHY_AFECTL_C1
);
1509 save_regs_phy
[1] = b43_phy_read(dev
, B43_NPHY_AFECTL_C2
);
1510 save_regs_phy
[2] = b43_phy_read(dev
,
1511 B43_NPHY_RFCTL_LUT_TRSW_UP1
);
1512 save_regs_phy
[3] = b43_phy_read(dev
,
1513 B43_NPHY_RFCTL_LUT_TRSW_UP2
);
1514 save_regs_phy
[4] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER1
);
1515 save_regs_phy
[5] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
1516 save_regs_phy
[6] = b43_phy_read(dev
, B43_NPHY_TXF_40CO_B1S0
);
1517 save_regs_phy
[7] = b43_phy_read(dev
, B43_NPHY_TXF_40CO_B32S1
);
1518 save_regs_phy
[8] = 0;
1520 save_regs_phy
[0] = b43_phy_read(dev
, B43_NPHY_AFECTL_C1
);
1521 save_regs_phy
[1] = b43_phy_read(dev
, B43_NPHY_AFECTL_C2
);
1522 save_regs_phy
[2] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
1523 save_regs_phy
[3] = b43_phy_read(dev
, B43_NPHY_RFCTL_CMD
);
1524 save_regs_phy
[4] = b43_phy_read(dev
, B43_NPHY_RFCTL_OVER
);
1525 save_regs_phy
[5] = b43_phy_read(dev
, B43_NPHY_RFCTL_RSSIO1
);
1526 save_regs_phy
[6] = b43_phy_read(dev
, B43_NPHY_RFCTL_RSSIO2
);
1527 save_regs_phy
[7] = 0;
1528 save_regs_phy
[8] = 0;
1531 b43_nphy_rssi_select(dev
, 5, rssi_type
);
1533 if (dev
->phy
.rev
< 2) {
1534 save_regs_phy
[8] = b43_phy_read(dev
, B43_NPHY_GPIO_SEL
);
1535 b43_phy_write(dev
, B43_NPHY_GPIO_SEL
, 5);
1538 for (i
= 0; i
< 4; i
++)
1541 for (i
= 0; i
< nsamp
; i
++) {
1542 if (dev
->phy
.rev
< 2) {
1543 s
[0] = b43_phy_read(dev
, B43_NPHY_GPIO_LOOUT
);
1544 s
[1] = b43_phy_read(dev
, B43_NPHY_GPIO_HIOUT
);
1546 s
[0] = b43_phy_read(dev
, B43_NPHY_RSSI1
);
1547 s
[1] = b43_phy_read(dev
, B43_NPHY_RSSI2
);
1550 buf
[0] += ((s8
)((s
[0] & 0x3F) << 2)) >> 2;
1551 buf
[1] += ((s8
)(((s
[0] >> 8) & 0x3F) << 2)) >> 2;
1552 buf
[2] += ((s8
)((s
[1] & 0x3F) << 2)) >> 2;
1553 buf
[3] += ((s8
)(((s
[1] >> 8) & 0x3F) << 2)) >> 2;
1555 out
= (buf
[0] & 0xFF) << 24 | (buf
[1] & 0xFF) << 16 |
1556 (buf
[2] & 0xFF) << 8 | (buf
[3] & 0xFF);
1558 if (dev
->phy
.rev
< 2)
1559 b43_phy_write(dev
, B43_NPHY_GPIO_SEL
, save_regs_phy
[8]);
1561 if (dev
->phy
.rev
>= 3) {
1562 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, save_regs_phy
[0]);
1563 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, save_regs_phy
[1]);
1564 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP1
,
1566 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP2
,
1568 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, save_regs_phy
[4]);
1569 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, save_regs_phy
[5]);
1570 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B1S0
, save_regs_phy
[6]);
1571 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B32S1
, save_regs_phy
[7]);
1573 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, save_regs_phy
[0]);
1574 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, save_regs_phy
[1]);
1575 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, save_regs_phy
[2]);
1576 b43_phy_write(dev
, B43_NPHY_RFCTL_CMD
, save_regs_phy
[3]);
1577 b43_phy_write(dev
, B43_NPHY_RFCTL_OVER
, save_regs_phy
[4]);
1578 b43_phy_write(dev
, B43_NPHY_RFCTL_RSSIO1
, save_regs_phy
[5]);
1579 b43_phy_write(dev
, B43_NPHY_RFCTL_RSSIO2
, save_regs_phy
[6]);
1585 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICalRev3 */
1586 static void b43_nphy_rev3_rssi_cal(struct b43_wldev
*dev
)
1588 struct b43_phy_n
*nphy
= dev
->phy
.n
;
1590 u16 saved_regs_phy_rfctl
[2];
1591 u16 saved_regs_phy
[13];
1592 u16 regs_to_store
[] = {
1593 B43_NPHY_AFECTL_OVER1
, B43_NPHY_AFECTL_OVER
,
1594 B43_NPHY_AFECTL_C1
, B43_NPHY_AFECTL_C2
,
1595 B43_NPHY_TXF_40CO_B1S1
, B43_NPHY_RFCTL_OVER
,
1596 B43_NPHY_TXF_40CO_B1S0
, B43_NPHY_TXF_40CO_B32S1
,
1598 B43_NPHY_RFCTL_LUT_TRSW_UP1
, B43_NPHY_RFCTL_LUT_TRSW_UP2
,
1599 B43_NPHY_RFCTL_RSSIO1
, B43_NPHY_RFCTL_RSSIO2
1605 u16 clip_off
[2] = { 0xFFFF, 0xFFFF };
1609 s32 results
[8][4] = { };
1610 s32 results_min
[4] = { };
1611 s32 poll_results
[4] = { };
1613 u16
*rssical_radio_regs
= NULL
;
1614 u16
*rssical_phy_regs
= NULL
;
1616 u16 r
; /* routing */
1618 int core
, i
, j
, vcm
;
1620 class = b43_nphy_classifier(dev
, 0, 0);
1621 b43_nphy_classifier(dev
, 7, 4);
1622 b43_nphy_read_clip_detection(dev
, clip_state
);
1623 b43_nphy_write_clip_detection(dev
, clip_off
);
1625 saved_regs_phy_rfctl
[0] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC1
);
1626 saved_regs_phy_rfctl
[1] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC2
);
1627 for (i
= 0; i
< ARRAY_SIZE(regs_to_store
); i
++)
1628 saved_regs_phy
[i
] = b43_phy_read(dev
, regs_to_store
[i
]);
1630 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_OFF
, 0, 7);
1631 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_TRSW
, 1, 7);
1632 b43_nphy_rf_ctl_override(dev
, 0x1, 0, 0, false);
1633 b43_nphy_rf_ctl_override(dev
, 0x2, 1, 0, false);
1634 b43_nphy_rf_ctl_override(dev
, 0x80, 1, 0, false);
1635 b43_nphy_rf_ctl_override(dev
, 0x40, 1, 0, false);
1637 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
1638 b43_nphy_rf_ctl_override(dev
, 0x20, 0, 0, false);
1639 b43_nphy_rf_ctl_override(dev
, 0x10, 1, 0, false);
1641 b43_nphy_rf_ctl_override(dev
, 0x10, 0, 0, false);
1642 b43_nphy_rf_ctl_override(dev
, 0x20, 1, 0, false);
1645 rx_core_state
= b43_nphy_get_rx_core_state(dev
);
1646 for (core
= 0; core
< 2; core
++) {
1647 if (!(rx_core_state
& (1 << core
)))
1649 r
= core
? B2056_RX1
: B2056_RX0
;
1650 b43_nphy_scale_offset_rssi(dev
, 0, 0, core
+ 1, N_RAIL_I
,
1652 b43_nphy_scale_offset_rssi(dev
, 0, 0, core
+ 1, N_RAIL_Q
,
1655 /* Grab RSSI results for every possible VCM */
1656 for (vcm
= 0; vcm
< 8; vcm
++) {
1657 b43_radio_maskset(dev
, r
| B2056_RX_RSSI_MISC
, 0xE3,
1659 b43_nphy_poll_rssi(dev
, N_RSSI_NB
, results
[vcm
], 8);
1662 /* Find out which VCM got the best results */
1663 for (i
= 0; i
< 4; i
+= 2) {
1665 s32 mind
= 0x100000;
1670 for (vcm
= 0; vcm
< 8; vcm
++) {
1671 currd
= results
[vcm
][i
] * results
[vcm
][i
] +
1672 results
[vcm
][i
+ 1] * results
[vcm
][i
];
1677 if (results
[vcm
][i
] < minpoll
)
1678 minpoll
= results
[vcm
][i
];
1681 results_min
[i
] = minpoll
;
1684 /* Select the best VCM */
1685 b43_radio_maskset(dev
, r
| B2056_RX_RSSI_MISC
, 0xE3,
1688 for (i
= 0; i
< 4; i
++) {
1691 offset
[i
] = -results
[vcm_final
][i
];
1693 offset
[i
] = -((abs(offset
[i
]) + 4) / 8);
1695 offset
[i
] = (offset
[i
] + 4) / 8;
1696 if (results_min
[i
] == 248)
1698 b43_nphy_scale_offset_rssi(dev
, 0, offset
[i
],
1699 (i
/ 2 == 0) ? 1 : 2,
1700 (i
% 2 == 0) ? N_RAIL_I
: N_RAIL_Q
,
1705 for (core
= 0; core
< 2; core
++) {
1706 if (!(rx_core_state
& (1 << core
)))
1708 for (i
= 0; i
< 2; i
++) {
1709 b43_nphy_scale_offset_rssi(dev
, 0, 0, core
+ 1,
1711 b43_nphy_scale_offset_rssi(dev
, 0, 0, core
+ 1,
1713 b43_nphy_poll_rssi(dev
, i
, poll_results
, 8);
1714 for (j
= 0; j
< 4; j
++) {
1715 if (j
/ 2 == core
) {
1716 offset
[j
] = 232 - poll_results
[j
];
1718 offset
[j
] = -(abs(offset
[j
] + 4) / 8);
1720 offset
[j
] = (offset
[j
] + 4) / 8;
1721 b43_nphy_scale_offset_rssi(dev
, 0,
1722 offset
[2 * core
], core
+ 1, j
% 2, i
);
1728 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, saved_regs_phy_rfctl
[0]);
1729 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, saved_regs_phy_rfctl
[1]);
1731 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
1733 b43_phy_set(dev
, B43_NPHY_TXF_40CO_B1S1
, 0x1);
1734 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
, B43_NPHY_RFCTL_CMD_START
);
1735 b43_phy_mask(dev
, B43_NPHY_TXF_40CO_B1S1
, ~0x1);
1737 b43_phy_set(dev
, B43_NPHY_RFCTL_OVER
, 0x1);
1738 b43_phy_set(dev
, B43_NPHY_RFCTL_CMD
, B43_NPHY_RFCTL_CMD_RXTX
);
1739 b43_phy_mask(dev
, B43_NPHY_TXF_40CO_B1S1
, ~0x1);
1741 for (i
= 0; i
< ARRAY_SIZE(regs_to_store
); i
++)
1742 b43_phy_write(dev
, regs_to_store
[i
], saved_regs_phy
[i
]);
1744 /* Store for future configuration */
1745 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
1746 rssical_radio_regs
= nphy
->rssical_cache
.rssical_radio_regs_2G
;
1747 rssical_phy_regs
= nphy
->rssical_cache
.rssical_phy_regs_2G
;
1749 rssical_radio_regs
= nphy
->rssical_cache
.rssical_radio_regs_5G
;
1750 rssical_phy_regs
= nphy
->rssical_cache
.rssical_phy_regs_5G
;
1752 if (dev
->phy
.rev
>= 7) {
1754 rssical_radio_regs
[0] = b43_radio_read(dev
, B2056_RX0
|
1755 B2056_RX_RSSI_MISC
);
1756 rssical_radio_regs
[1] = b43_radio_read(dev
, B2056_RX1
|
1757 B2056_RX_RSSI_MISC
);
1759 rssical_phy_regs
[0] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0I_RSSI_Z
);
1760 rssical_phy_regs
[1] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Z
);
1761 rssical_phy_regs
[2] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1I_RSSI_Z
);
1762 rssical_phy_regs
[3] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Z
);
1763 rssical_phy_regs
[4] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0I_RSSI_X
);
1764 rssical_phy_regs
[5] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0Q_RSSI_X
);
1765 rssical_phy_regs
[6] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1I_RSSI_X
);
1766 rssical_phy_regs
[7] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1Q_RSSI_X
);
1767 rssical_phy_regs
[8] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0I_RSSI_Y
);
1768 rssical_phy_regs
[9] = b43_phy_read(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Y
);
1769 rssical_phy_regs
[10] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1I_RSSI_Y
);
1770 rssical_phy_regs
[11] = b43_phy_read(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Y
);
1772 /* Remember for which channel we store configuration */
1773 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
1774 nphy
->rssical_chanspec_2G
.center_freq
= dev
->phy
.channel_freq
;
1776 nphy
->rssical_chanspec_5G
.center_freq
= dev
->phy
.channel_freq
;
1778 /* End of calibration, restore configuration */
1779 b43_nphy_classifier(dev
, 7, class);
1780 b43_nphy_write_clip_detection(dev
, clip_state
);
1783 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICal */
1784 static void b43_nphy_rev2_rssi_cal(struct b43_wldev
*dev
, enum n_rssi_type type
)
1789 u16
class, override
;
1790 u8 regs_save_radio
[2];
1791 u16 regs_save_phy
[2];
1798 u16 clip_off
[2] = { 0xFFFF, 0xFFFF };
1799 s32 results_min
[4] = { };
1800 u8 vcm_final
[4] = { };
1801 s32 results
[4][4] = { };
1802 s32 miniq
[4][2] = { };
1804 if (type
== N_RSSI_NB
) {
1807 } else if (type
== N_RSSI_W1
|| type
== N_RSSI_W2
) {
1815 class = b43_nphy_classifier(dev
, 0, 0);
1816 b43_nphy_classifier(dev
, 7, 4);
1817 b43_nphy_read_clip_detection(dev
, clip_state
);
1818 b43_nphy_write_clip_detection(dev
, clip_off
);
1820 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
)
1825 regs_save_phy
[0] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC1
);
1826 regs_save_radio
[0] = b43_radio_read(dev
, B2055_C1_PD_RXTX
);
1827 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, override
);
1828 b43_radio_write(dev
, B2055_C1_PD_RXTX
, val
);
1830 regs_save_phy
[1] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC2
);
1831 regs_save_radio
[1] = b43_radio_read(dev
, B2055_C2_PD_RXTX
);
1832 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, override
);
1833 b43_radio_write(dev
, B2055_C2_PD_RXTX
, val
);
1835 state
[0] = b43_radio_read(dev
, B2055_C1_PD_RSSIMISC
) & 0x07;
1836 state
[1] = b43_radio_read(dev
, B2055_C2_PD_RSSIMISC
) & 0x07;
1837 b43_radio_mask(dev
, B2055_C1_PD_RSSIMISC
, 0xF8);
1838 b43_radio_mask(dev
, B2055_C2_PD_RSSIMISC
, 0xF8);
1839 state
[2] = b43_radio_read(dev
, B2055_C1_SP_RSSI
) & 0x07;
1840 state
[3] = b43_radio_read(dev
, B2055_C2_SP_RSSI
) & 0x07;
1842 b43_nphy_rssi_select(dev
, 5, type
);
1843 b43_nphy_scale_offset_rssi(dev
, 0, 0, 5, N_RAIL_I
, type
);
1844 b43_nphy_scale_offset_rssi(dev
, 0, 0, 5, N_RAIL_Q
, type
);
1846 for (vcm
= 0; vcm
< 4; vcm
++) {
1848 for (j
= 0; j
< 4; j
++)
1850 if (type
!= N_RSSI_W2
)
1851 b43_nphy_set_rssi_2055_vcm(dev
, type
, tmp
);
1852 b43_nphy_poll_rssi(dev
, type
, results
[vcm
], 8);
1853 if (type
== N_RSSI_W1
|| type
== N_RSSI_W2
)
1854 for (j
= 0; j
< 2; j
++)
1855 miniq
[vcm
][j
] = min(results
[vcm
][2 * j
],
1856 results
[vcm
][2 * j
+ 1]);
1859 for (i
= 0; i
< 4; i
++) {
1860 s32 mind
= 0x100000;
1864 for (vcm
= 0; vcm
< 4; vcm
++) {
1865 if (type
== N_RSSI_NB
)
1866 currd
= abs(results
[vcm
][i
] - code
* 8);
1868 currd
= abs(miniq
[vcm
][i
/ 2] - code
* 8);
1875 if (results
[vcm
][i
] < minpoll
)
1876 minpoll
= results
[vcm
][i
];
1878 results_min
[i
] = minpoll
;
1879 vcm_final
[i
] = minvcm
;
1882 if (type
!= N_RSSI_W2
)
1883 b43_nphy_set_rssi_2055_vcm(dev
, type
, vcm_final
);
1885 for (i
= 0; i
< 4; i
++) {
1886 offset
[i
] = (code
* 8) - results
[vcm_final
[i
]][i
];
1889 offset
[i
] = -((abs(offset
[i
]) + 4) / 8);
1891 offset
[i
] = (offset
[i
] + 4) / 8;
1893 if (results_min
[i
] == 248)
1894 offset
[i
] = code
- 32;
1896 core
= (i
/ 2) ? 2 : 1;
1897 rail
= (i
% 2) ? N_RAIL_Q
: N_RAIL_I
;
1899 b43_nphy_scale_offset_rssi(dev
, 0, offset
[i
], core
, rail
,
1903 b43_radio_maskset(dev
, B2055_C1_PD_RSSIMISC
, 0xF8, state
[0]);
1904 b43_radio_maskset(dev
, B2055_C2_PD_RSSIMISC
, 0xF8, state
[1]);
1908 b43_nphy_rssi_select(dev
, 1, N_RSSI_NB
);
1911 b43_nphy_rssi_select(dev
, 1, N_RSSI_W1
);
1914 b43_nphy_rssi_select(dev
, 1, N_RSSI_W2
);
1917 b43_nphy_rssi_select(dev
, 1, N_RSSI_W2
);
1923 b43_nphy_rssi_select(dev
, 2, N_RSSI_NB
);
1926 b43_nphy_rssi_select(dev
, 2, N_RSSI_W1
);
1929 b43_nphy_rssi_select(dev
, 2, N_RSSI_W2
);
1933 b43_nphy_rssi_select(dev
, 0, type
);
1935 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, regs_save_phy
[0]);
1936 b43_radio_write(dev
, B2055_C1_PD_RXTX
, regs_save_radio
[0]);
1937 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, regs_save_phy
[1]);
1938 b43_radio_write(dev
, B2055_C2_PD_RXTX
, regs_save_radio
[1]);
1940 b43_nphy_classifier(dev
, 7, class);
1941 b43_nphy_write_clip_detection(dev
, clip_state
);
1942 /* Specs don't say about reset here, but it makes wl and b43 dumps
1943 identical, it really seems wl performs this */
1944 b43_nphy_reset_cca(dev
);
1949 * http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICal
1951 static void b43_nphy_rssi_cal(struct b43_wldev
*dev
)
1953 if (dev
->phy
.rev
>= 3) {
1954 b43_nphy_rev3_rssi_cal(dev
);
1956 b43_nphy_rev2_rssi_cal(dev
, N_RSSI_NB
);
1957 b43_nphy_rev2_rssi_cal(dev
, N_RSSI_W1
);
1958 b43_nphy_rev2_rssi_cal(dev
, N_RSSI_W2
);
1962 /**************************************************
1964 **************************************************/
1966 static void b43_nphy_gain_ctl_workarounds_rev3plus(struct b43_wldev
*dev
)
1968 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
1973 struct nphy_gain_ctl_workaround_entry
*e
;
1974 u8 lpf_gain
[6] = { 0x00, 0x06, 0x0C, 0x12, 0x12, 0x12 };
1975 u8 lpf_bits
[6] = { 0, 1, 2, 3, 3, 3 };
1977 /* Prepare values */
1978 ghz5
= b43_phy_read(dev
, B43_NPHY_BANDCTL
)
1979 & B43_NPHY_BANDCTL_5GHZ
;
1980 ext_lna
= ghz5
? sprom
->boardflags_hi
& B43_BFH_EXTLNA_5GHZ
:
1981 sprom
->boardflags_lo
& B43_BFL_EXTLNA
;
1982 e
= b43_nphy_get_gain_ctl_workaround_ent(dev
, ghz5
, ext_lna
);
1983 if (ghz5
&& dev
->phy
.rev
>= 5)
1988 b43_phy_set(dev
, B43_NPHY_RXCTL
, 0x0040);
1990 /* Set Clip 2 detect */
1991 b43_phy_set(dev
, B43_NPHY_C1_CGAINI
, B43_NPHY_C1_CGAINI_CL2DETECT
);
1992 b43_phy_set(dev
, B43_NPHY_C2_CGAINI
, B43_NPHY_C2_CGAINI_CL2DETECT
);
1994 b43_radio_write(dev
, B2056_RX0
| B2056_RX_BIASPOLE_LNAG1_IDAC
,
1996 b43_radio_write(dev
, B2056_RX1
| B2056_RX_BIASPOLE_LNAG1_IDAC
,
1998 b43_radio_write(dev
, B2056_RX0
| B2056_RX_LNAG2_IDAC
, 0xF0);
1999 b43_radio_write(dev
, B2056_RX1
| B2056_RX_LNAG2_IDAC
, 0xF0);
2000 b43_radio_write(dev
, B2056_RX0
| B2056_RX_RSSI_POLE
, 0x00);
2001 b43_radio_write(dev
, B2056_RX1
| B2056_RX_RSSI_POLE
, 0x00);
2002 b43_radio_write(dev
, B2056_RX0
| B2056_RX_RSSI_GAIN
,
2004 b43_radio_write(dev
, B2056_RX1
| B2056_RX_RSSI_GAIN
,
2006 b43_radio_write(dev
, B2056_RX0
| B2056_RX_BIASPOLE_LNAA1_IDAC
,
2008 b43_radio_write(dev
, B2056_RX1
| B2056_RX_BIASPOLE_LNAA1_IDAC
,
2010 b43_radio_write(dev
, B2056_RX0
| B2056_RX_LNAA2_IDAC
, 0xFF);
2011 b43_radio_write(dev
, B2056_RX1
| B2056_RX_LNAA2_IDAC
, 0xFF);
2013 b43_ntab_write_bulk(dev
, B43_NTAB8(0, 8), 4, e
->lna1_gain
);
2014 b43_ntab_write_bulk(dev
, B43_NTAB8(1, 8), 4, e
->lna1_gain
);
2015 b43_ntab_write_bulk(dev
, B43_NTAB8(0, 16), 4, e
->lna2_gain
);
2016 b43_ntab_write_bulk(dev
, B43_NTAB8(1, 16), 4, e
->lna2_gain
);
2017 b43_ntab_write_bulk(dev
, B43_NTAB8(0, 32), 10, e
->gain_db
);
2018 b43_ntab_write_bulk(dev
, B43_NTAB8(1, 32), 10, e
->gain_db
);
2019 b43_ntab_write_bulk(dev
, B43_NTAB8(2, 32), 10, e
->gain_bits
);
2020 b43_ntab_write_bulk(dev
, B43_NTAB8(3, 32), 10, e
->gain_bits
);
2021 b43_ntab_write_bulk(dev
, B43_NTAB8(0, 0x40), 6, lpf_gain
);
2022 b43_ntab_write_bulk(dev
, B43_NTAB8(1, 0x40), 6, lpf_gain
);
2023 b43_ntab_write_bulk(dev
, B43_NTAB8(2, 0x40), 6, lpf_bits
);
2024 b43_ntab_write_bulk(dev
, B43_NTAB8(3, 0x40), 6, lpf_bits
);
2026 b43_phy_write(dev
, B43_NPHY_REV3_C1_INITGAIN_A
, e
->init_gain
);
2027 b43_phy_write(dev
, B43_NPHY_REV3_C2_INITGAIN_A
, e
->init_gain
);
2029 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x106), 2,
2032 b43_phy_write(dev
, B43_NPHY_REV3_C1_CLIP_HIGAIN_A
, e
->cliphi_gain
);
2033 b43_phy_write(dev
, B43_NPHY_REV3_C2_CLIP_HIGAIN_A
, e
->cliphi_gain
);
2034 b43_phy_write(dev
, B43_NPHY_REV3_C1_CLIP_MEDGAIN_A
, e
->clipmd_gain
);
2035 b43_phy_write(dev
, B43_NPHY_REV3_C2_CLIP_MEDGAIN_A
, e
->clipmd_gain
);
2036 b43_phy_write(dev
, B43_NPHY_REV3_C1_CLIP_LOGAIN_A
, e
->cliplo_gain
);
2037 b43_phy_write(dev
, B43_NPHY_REV3_C2_CLIP_LOGAIN_A
, e
->cliplo_gain
);
2039 b43_phy_maskset(dev
, B43_NPHY_CRSMINPOWER0
, 0xFF00, e
->crsmin
);
2040 b43_phy_maskset(dev
, B43_NPHY_CRSMINPOWERL0
, 0xFF00, e
->crsminl
);
2041 b43_phy_maskset(dev
, B43_NPHY_CRSMINPOWERU0
, 0xFF00, e
->crsminu
);
2042 b43_phy_write(dev
, B43_NPHY_C1_NBCLIPTHRES
, e
->nbclip
);
2043 b43_phy_write(dev
, B43_NPHY_C2_NBCLIPTHRES
, e
->nbclip
);
2044 b43_phy_maskset(dev
, B43_NPHY_C1_CLIPWBTHRES
,
2045 ~B43_NPHY_C1_CLIPWBTHRES_CLIP2
, e
->wlclip
);
2046 b43_phy_maskset(dev
, B43_NPHY_C2_CLIPWBTHRES
,
2047 ~B43_NPHY_C2_CLIPWBTHRES_CLIP2
, e
->wlclip
);
2048 b43_phy_write(dev
, B43_NPHY_CCK_SHIFTB_REF
, 0x809C);
2051 static void b43_nphy_gain_ctl_workarounds_rev1_2(struct b43_wldev
*dev
)
2053 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2058 u8 rfseq_events
[3] = { 6, 8, 7 };
2059 u8 rfseq_delays
[3] = { 10, 30, 1 };
2061 /* Set Clip 2 detect */
2062 b43_phy_set(dev
, B43_NPHY_C1_CGAINI
, B43_NPHY_C1_CGAINI_CL2DETECT
);
2063 b43_phy_set(dev
, B43_NPHY_C2_CGAINI
, B43_NPHY_C2_CGAINI_CL2DETECT
);
2065 /* Set narrowband clip threshold */
2066 b43_phy_write(dev
, B43_NPHY_C1_NBCLIPTHRES
, 0x84);
2067 b43_phy_write(dev
, B43_NPHY_C2_NBCLIPTHRES
, 0x84);
2069 if (!dev
->phy
.is_40mhz
) {
2070 /* Set dwell lengths */
2071 b43_phy_write(dev
, B43_NPHY_CLIP1_NBDWELL_LEN
, 0x002B);
2072 b43_phy_write(dev
, B43_NPHY_CLIP2_NBDWELL_LEN
, 0x002B);
2073 b43_phy_write(dev
, B43_NPHY_W1CLIP1_DWELL_LEN
, 0x0009);
2074 b43_phy_write(dev
, B43_NPHY_W1CLIP2_DWELL_LEN
, 0x0009);
2077 /* Set wideband clip 2 threshold */
2078 b43_phy_maskset(dev
, B43_NPHY_C1_CLIPWBTHRES
,
2079 ~B43_NPHY_C1_CLIPWBTHRES_CLIP2
, 21);
2080 b43_phy_maskset(dev
, B43_NPHY_C2_CLIPWBTHRES
,
2081 ~B43_NPHY_C2_CLIPWBTHRES_CLIP2
, 21);
2083 if (!dev
->phy
.is_40mhz
) {
2084 b43_phy_maskset(dev
, B43_NPHY_C1_CGAINI
,
2085 ~B43_NPHY_C1_CGAINI_GAINBKOFF
, 0x1);
2086 b43_phy_maskset(dev
, B43_NPHY_C2_CGAINI
,
2087 ~B43_NPHY_C2_CGAINI_GAINBKOFF
, 0x1);
2088 b43_phy_maskset(dev
, B43_NPHY_C1_CCK_CGAINI
,
2089 ~B43_NPHY_C1_CCK_CGAINI_GAINBKOFF
, 0x1);
2090 b43_phy_maskset(dev
, B43_NPHY_C2_CCK_CGAINI
,
2091 ~B43_NPHY_C2_CCK_CGAINI_GAINBKOFF
, 0x1);
2094 b43_phy_write(dev
, B43_NPHY_CCK_SHIFTB_REF
, 0x809C);
2096 if (nphy
->gain_boost
) {
2097 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
&&
2103 code
= dev
->phy
.is_40mhz
? 6 : 7;
2106 /* Set HPVGA2 index */
2107 b43_phy_maskset(dev
, B43_NPHY_C1_INITGAIN
, ~B43_NPHY_C1_INITGAIN_HPVGA2
,
2108 code
<< B43_NPHY_C1_INITGAIN_HPVGA2_SHIFT
);
2109 b43_phy_maskset(dev
, B43_NPHY_C2_INITGAIN
, ~B43_NPHY_C2_INITGAIN_HPVGA2
,
2110 code
<< B43_NPHY_C2_INITGAIN_HPVGA2_SHIFT
);
2112 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x1D06);
2113 /* specs say about 2 loops, but wl does 4 */
2114 for (i
= 0; i
< 4; i
++)
2115 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, (code
<< 8 | 0x7C));
2117 b43_nphy_adjust_lna_gain_table(dev
);
2119 if (nphy
->elna_gain_config
) {
2120 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x0808);
2121 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x0);
2122 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2123 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2124 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2126 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x0C08);
2127 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x0);
2128 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2129 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2130 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0x1);
2132 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x1D06);
2133 /* specs say about 2 loops, but wl does 4 */
2134 for (i
= 0; i
< 4; i
++)
2135 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
,
2136 (code
<< 8 | 0x74));
2139 if (dev
->phy
.rev
== 2) {
2140 for (i
= 0; i
< 4; i
++) {
2141 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
,
2142 (0x0400 * i
) + 0x0020);
2143 for (j
= 0; j
< 21; j
++) {
2144 tmp
= j
* (i
< 2 ? 3 : 1);
2146 B43_NPHY_TABLE_DATALO
, tmp
);
2151 b43_nphy_set_rf_sequence(dev
, 5, rfseq_events
, rfseq_delays
, 3);
2152 b43_phy_maskset(dev
, B43_NPHY_OVER_DGAIN1
,
2153 ~B43_NPHY_OVER_DGAIN_CCKDGECV
& 0xFFFF,
2154 0x5A << B43_NPHY_OVER_DGAIN_CCKDGECV_SHIFT
);
2156 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
2157 b43_phy_maskset(dev
, B43_PHY_N(0xC5D), 0xFF80, 4);
2160 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/WorkaroundsGainCtrl */
2161 static void b43_nphy_gain_ctl_workarounds(struct b43_wldev
*dev
)
2163 if (dev
->phy
.rev
>= 7)
2165 else if (dev
->phy
.rev
>= 3)
2166 b43_nphy_gain_ctl_workarounds_rev3plus(dev
);
2168 b43_nphy_gain_ctl_workarounds_rev1_2(dev
);
2171 /* http://bcm-v4.sipsolutions.net/PHY/N/Read_Lpf_Bw_Ctl */
2172 static u16
b43_nphy_read_lpf_ctl(struct b43_wldev
*dev
, u16 offset
)
2175 offset
= (dev
->phy
.is_40mhz
) ? 0x159 : 0x154;
2176 return b43_ntab_read(dev
, B43_NTAB16(7, offset
)) & 0x7;
2179 static void b43_nphy_workarounds_rev7plus(struct b43_wldev
*dev
)
2181 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
2182 struct b43_phy
*phy
= &dev
->phy
;
2184 u8 rx2tx_events_ipa
[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
2186 u8 rx2tx_delays_ipa
[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
2188 u16 ntab7_15e_16e
[] = { 0x10f, 0x10f };
2189 u8 ntab7_138_146
[] = { 0x11, 0x11 };
2190 u8 ntab7_133
[] = { 0x77, 0x11, 0x11 };
2192 u16 lpf_20
, lpf_40
, lpf_11b
;
2193 u16 bcap_val
, bcap_val_11b
, bcap_val_11n_20
, bcap_val_11n_40
;
2194 u16 scap_val
, scap_val_11b
, scap_val_11n_20
, scap_val_11n_40
;
2195 bool rccal_ovrd
= false;
2197 u16 rx2tx_lut_20_11b
, rx2tx_lut_20_11n
, rx2tx_lut_40_11n
;
2198 u16 bias
, conv
, filt
;
2203 if (phy
->rev
== 7) {
2204 b43_phy_set(dev
, B43_NPHY_FINERX2_CGC
, 0x10);
2205 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN0
, 0xFF80, 0x0020);
2206 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN0
, 0x80FF, 0x2700);
2207 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN1
, 0xFF80, 0x002E);
2208 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN1
, 0x80FF, 0x3300);
2209 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN2
, 0xFF80, 0x0037);
2210 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN2
, 0x80FF, 0x3A00);
2211 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN3
, 0xFF80, 0x003C);
2212 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN3
, 0x80FF, 0x3E00);
2213 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN4
, 0xFF80, 0x003E);
2214 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN4
, 0x80FF, 0x3F00);
2215 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN5
, 0xFF80, 0x0040);
2216 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN5
, 0x80FF, 0x4000);
2217 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN6
, 0xFF80, 0x0040);
2218 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN6
, 0x80FF, 0x4000);
2219 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN7
, 0xFF80, 0x0040);
2220 b43_phy_maskset(dev
, B43_NPHY_FREQGAIN7
, 0x80FF, 0x4000);
2222 if (phy
->rev
<= 8) {
2223 b43_phy_write(dev
, B43_NPHY_FORCEFRONT0
, 0x1B0);
2224 b43_phy_write(dev
, B43_NPHY_FORCEFRONT1
, 0x1B0);
2227 b43_phy_maskset(dev
, B43_NPHY_TXTAILCNT
, ~0xFF, 0x72);
2229 b43_ntab_write(dev
, B43_NTAB16(8, 0x00), 2);
2230 b43_ntab_write(dev
, B43_NTAB16(8, 0x10), 2);
2231 tmp32
= b43_ntab_read(dev
, B43_NTAB32(30, 0));
2233 b43_ntab_write(dev
, B43_NTAB32(30, 0), tmp32
);
2234 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x15e), 2, ntab7_15e_16e
);
2235 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x16e), 2, ntab7_15e_16e
);
2237 if (b43_nphy_ipa(dev
))
2238 b43_nphy_set_rf_sequence(dev
, 0, rx2tx_events_ipa
,
2239 rx2tx_delays_ipa
, ARRAY_SIZE(rx2tx_events_ipa
));
2241 b43_phy_maskset(dev
, B43_NPHY_EPS_OVERRIDEI_0
, 0x3FFF, 0x4000);
2242 b43_phy_maskset(dev
, B43_NPHY_EPS_OVERRIDEI_1
, 0x3FFF, 0x4000);
2244 lpf_20
= b43_nphy_read_lpf_ctl(dev
, 0x154);
2245 lpf_40
= b43_nphy_read_lpf_ctl(dev
, 0x159);
2246 lpf_11b
= b43_nphy_read_lpf_ctl(dev
, 0x152);
2247 if (b43_nphy_ipa(dev
)) {
2248 if ((phy
->radio_rev
== 5 && phy
->is_40mhz
) ||
2249 phy
->radio_rev
== 7 || phy
->radio_rev
== 8) {
2250 bcap_val
= b43_radio_read(dev
, 0x16b);
2251 scap_val
= b43_radio_read(dev
, 0x16a);
2252 scap_val_11b
= scap_val
;
2253 bcap_val_11b
= bcap_val
;
2254 if (phy
->radio_rev
== 5 && phy
->is_40mhz
) {
2255 scap_val_11n_20
= scap_val
;
2256 bcap_val_11n_20
= bcap_val
;
2257 scap_val_11n_40
= bcap_val_11n_40
= 0xc;
2259 } else { /* Rev 7/8 */
2262 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
2263 scap_val_11n_20
= 0xc;
2264 bcap_val_11n_20
= 0xc;
2265 scap_val_11n_40
= 0xa;
2266 bcap_val_11n_40
= 0xa;
2268 scap_val_11n_20
= 0x14;
2269 bcap_val_11n_20
= 0x14;
2270 scap_val_11n_40
= 0xf;
2271 bcap_val_11n_40
= 0xf;
2277 if (phy
->radio_rev
== 5) {
2280 bcap_val
= b43_radio_read(dev
, 0x16b);
2281 scap_val
= b43_radio_read(dev
, 0x16a);
2282 scap_val_11b
= scap_val
;
2283 bcap_val_11b
= bcap_val
;
2284 scap_val_11n_20
= 0x11;
2285 scap_val_11n_40
= 0x11;
2286 bcap_val_11n_20
= 0x13;
2287 bcap_val_11n_40
= 0x13;
2292 rx2tx_lut_20_11b
= (bcap_val_11b
<< 8) |
2293 (scap_val_11b
<< 3) |
2295 rx2tx_lut_20_11n
= (bcap_val_11n_20
<< 8) |
2296 (scap_val_11n_20
<< 3) |
2298 rx2tx_lut_40_11n
= (bcap_val_11n_40
<< 8) |
2299 (scap_val_11n_40
<< 3) |
2301 for (core
= 0; core
< 2; core
++) {
2302 b43_ntab_write(dev
, B43_NTAB16(7, 0x152 + core
* 16),
2304 b43_ntab_write(dev
, B43_NTAB16(7, 0x153 + core
* 16),
2306 b43_ntab_write(dev
, B43_NTAB16(7, 0x154 + core
* 16),
2308 b43_ntab_write(dev
, B43_NTAB16(7, 0x155 + core
* 16),
2310 b43_ntab_write(dev
, B43_NTAB16(7, 0x156 + core
* 16),
2312 b43_ntab_write(dev
, B43_NTAB16(7, 0x157 + core
* 16),
2314 b43_ntab_write(dev
, B43_NTAB16(7, 0x158 + core
* 16),
2316 b43_ntab_write(dev
, B43_NTAB16(7, 0x159 + core
* 16),
2319 b43_nphy_rf_ctl_override_rev7(dev
, 16, 1, 3, false, 2);
2321 b43_phy_write(dev
, 0x32F, 0x3);
2322 if (phy
->radio_rev
== 4 || phy
->radio_rev
== 6)
2323 b43_nphy_rf_ctl_override_rev7(dev
, 4, 1, 3, false, 0);
2325 if (phy
->radio_rev
== 3 || phy
->radio_rev
== 4 || phy
->radio_rev
== 6) {
2326 if (sprom
->revision
&&
2327 sprom
->boardflags2_hi
& B43_BFH2_IPALVLSHIFT_3P3
) {
2328 b43_radio_write(dev
, 0x5, 0x05);
2329 b43_radio_write(dev
, 0x6, 0x30);
2330 b43_radio_write(dev
, 0x7, 0x00);
2331 b43_radio_set(dev
, 0x4f, 0x1);
2332 b43_radio_set(dev
, 0xd4, 0x1);
2341 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
2342 for (core
= 0; core
< 2; core
++) {
2344 b43_radio_write(dev
, 0x5F, bias
);
2345 b43_radio_write(dev
, 0x64, conv
);
2346 b43_radio_write(dev
, 0x66, filt
);
2348 b43_radio_write(dev
, 0xE8, bias
);
2349 b43_radio_write(dev
, 0xE9, conv
);
2350 b43_radio_write(dev
, 0xEB, filt
);
2356 if (b43_nphy_ipa(dev
)) {
2357 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
2358 if (phy
->radio_rev
== 3 || phy
->radio_rev
== 4 ||
2359 phy
->radio_rev
== 6) {
2360 for (core
= 0; core
< 2; core
++) {
2362 b43_radio_write(dev
, 0x51,
2365 b43_radio_write(dev
, 0xd6,
2369 if (phy
->radio_rev
== 3) {
2370 for (core
= 0; core
< 2; core
++) {
2372 b43_radio_write(dev
, 0x64,
2374 b43_radio_write(dev
, 0x5F,
2376 b43_radio_write(dev
, 0x66,
2378 b43_radio_write(dev
, 0x59,
2380 b43_radio_write(dev
, 0x80,
2383 b43_radio_write(dev
, 0x69,
2385 b43_radio_write(dev
, 0xE8,
2387 b43_radio_write(dev
, 0xEB,
2389 b43_radio_write(dev
, 0xDE,
2391 b43_radio_write(dev
, 0x105,
2395 } else if (phy
->radio_rev
== 7 || phy
->radio_rev
== 8) {
2396 if (!phy
->is_40mhz
) {
2397 b43_radio_write(dev
, 0x5F, 0x14);
2398 b43_radio_write(dev
, 0xE8, 0x12);
2400 b43_radio_write(dev
, 0x5F, 0x16);
2401 b43_radio_write(dev
, 0xE8, 0x16);
2405 u16 freq
= phy
->channel_freq
;
2406 if ((freq
>= 5180 && freq
<= 5230) ||
2407 (freq
>= 5745 && freq
<= 5805)) {
2408 b43_radio_write(dev
, 0x7D, 0xFF);
2409 b43_radio_write(dev
, 0xFE, 0xFF);
2413 if (phy
->radio_rev
!= 5) {
2414 for (core
= 0; core
< 2; core
++) {
2416 b43_radio_write(dev
, 0x5c, 0x61);
2417 b43_radio_write(dev
, 0x51, 0x70);
2419 b43_radio_write(dev
, 0xe1, 0x61);
2420 b43_radio_write(dev
, 0xd6, 0x70);
2426 if (phy
->radio_rev
== 4) {
2427 b43_ntab_write(dev
, B43_NTAB16(8, 0x05), 0x20);
2428 b43_ntab_write(dev
, B43_NTAB16(8, 0x15), 0x20);
2429 for (core
= 0; core
< 2; core
++) {
2431 b43_radio_write(dev
, 0x1a1, 0x00);
2432 b43_radio_write(dev
, 0x1a2, 0x3f);
2433 b43_radio_write(dev
, 0x1a6, 0x3f);
2435 b43_radio_write(dev
, 0x1a7, 0x00);
2436 b43_radio_write(dev
, 0x1ab, 0x3f);
2437 b43_radio_write(dev
, 0x1ac, 0x3f);
2441 b43_phy_set(dev
, B43_NPHY_AFECTL_C1
, 0x4);
2442 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER1
, 0x4);
2443 b43_phy_set(dev
, B43_NPHY_AFECTL_C2
, 0x4);
2444 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x4);
2446 b43_phy_mask(dev
, B43_NPHY_AFECTL_C1
, ~0x1);
2447 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER1
, 0x1);
2448 b43_phy_mask(dev
, B43_NPHY_AFECTL_C2
, ~0x1);
2449 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x1);
2450 b43_ntab_write(dev
, B43_NTAB16(8, 0x05), 0x20);
2451 b43_ntab_write(dev
, B43_NTAB16(8, 0x15), 0x20);
2453 b43_phy_mask(dev
, B43_NPHY_AFECTL_C1
, ~0x4);
2454 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER1
, ~0x4);
2455 b43_phy_mask(dev
, B43_NPHY_AFECTL_C2
, ~0x4);
2456 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER
, ~0x4);
2459 b43_phy_write(dev
, B43_NPHY_ENDROP_TLEN
, 0x2);
2461 b43_ntab_write(dev
, B43_NTAB32(16, 0x100), 20);
2462 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x138), 2, ntab7_138_146
);
2463 b43_ntab_write(dev
, B43_NTAB16(7, 0x141), 0x77);
2464 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x133), 3, ntab7_133
);
2465 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x146), 2, ntab7_138_146
);
2466 b43_ntab_write(dev
, B43_NTAB16(7, 0x123), 0x77);
2467 b43_ntab_write(dev
, B43_NTAB16(7, 0x12A), 0x77);
2469 if (!phy
->is_40mhz
) {
2470 b43_ntab_write(dev
, B43_NTAB32(16, 0x03), 0x18D);
2471 b43_ntab_write(dev
, B43_NTAB32(16, 0x7F), 0x18D);
2473 b43_ntab_write(dev
, B43_NTAB32(16, 0x03), 0x14D);
2474 b43_ntab_write(dev
, B43_NTAB32(16, 0x7F), 0x14D);
2477 b43_nphy_gain_ctl_workarounds(dev
);
2480 b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x08), 4,
2481 aux_adc_vmid_rev7_core0);
2482 b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x18), 4,
2483 aux_adc_vmid_rev7_core1);
2484 b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x0C), 4,
2486 b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x1C), 4,
2491 static void b43_nphy_workarounds_rev3plus(struct b43_wldev
*dev
)
2493 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2494 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
2497 u8 tx2rx_events
[8] = { 0x4, 0x3, 0x6, 0x5, 0x2, 0x1, 0x8, 0x1F };
2498 u8 tx2rx_delays
[8] = { 8, 4, 2, 2, 4, 4, 6, 1 };
2500 u8 rx2tx_events_ipa
[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
2502 u8 rx2tx_delays_ipa
[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
2503 u8 rx2tx_events
[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0x3, 0x4, 0x1F };
2504 u8 rx2tx_delays
[9] = { 8, 6, 6, 4, 4, 18, 42, 1, 1 };
2509 b43_phy_write(dev
, B43_NPHY_FORCEFRONT0
, 0x1f8);
2510 b43_phy_write(dev
, B43_NPHY_FORCEFRONT1
, 0x1f8);
2512 tmp32
= b43_ntab_read(dev
, B43_NTAB32(30, 0));
2514 b43_ntab_write(dev
, B43_NTAB32(30, 0), tmp32
);
2516 b43_phy_write(dev
, B43_NPHY_PHASETR_A0
, 0x0125);
2517 b43_phy_write(dev
, B43_NPHY_PHASETR_A1
, 0x01B3);
2518 b43_phy_write(dev
, B43_NPHY_PHASETR_A2
, 0x0105);
2519 b43_phy_write(dev
, B43_NPHY_PHASETR_B0
, 0x016E);
2520 b43_phy_write(dev
, B43_NPHY_PHASETR_B1
, 0x00CD);
2521 b43_phy_write(dev
, B43_NPHY_PHASETR_B2
, 0x0020);
2523 b43_phy_write(dev
, B43_NPHY_REV3_C1_CLIP_LOGAIN_B
, 0x000C);
2524 b43_phy_write(dev
, B43_NPHY_REV3_C2_CLIP_LOGAIN_B
, 0x000C);
2527 b43_nphy_set_rf_sequence(dev
, 1, tx2rx_events
, tx2rx_delays
,
2528 ARRAY_SIZE(tx2rx_events
));
2531 if (b43_nphy_ipa(dev
))
2532 b43_nphy_set_rf_sequence(dev
, 0, rx2tx_events_ipa
,
2533 rx2tx_delays_ipa
, ARRAY_SIZE(rx2tx_events_ipa
));
2534 if (nphy
->hw_phyrxchain
!= 3 &&
2535 nphy
->hw_phyrxchain
!= nphy
->hw_phytxchain
) {
2536 if (b43_nphy_ipa(dev
)) {
2537 rx2tx_delays
[5] = 59;
2538 rx2tx_delays
[6] = 1;
2539 rx2tx_events
[7] = 0x1F;
2541 b43_nphy_set_rf_sequence(dev
, 0, rx2tx_events
, rx2tx_delays
,
2542 ARRAY_SIZE(rx2tx_events
));
2545 tmp16
= (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) ?
2547 b43_phy_write(dev
, B43_NPHY_ENDROP_TLEN
, tmp16
);
2549 b43_phy_maskset(dev
, B43_NPHY_SGILTRNOFFSET
, 0xF0FF, 0x0700);
2551 if (!dev
->phy
.is_40mhz
) {
2552 b43_ntab_write(dev
, B43_NTAB32(16, 3), 0x18D);
2553 b43_ntab_write(dev
, B43_NTAB32(16, 127), 0x18D);
2555 b43_ntab_write(dev
, B43_NTAB32(16, 3), 0x14D);
2556 b43_ntab_write(dev
, B43_NTAB32(16, 127), 0x14D);
2559 b43_nphy_gain_ctl_workarounds(dev
);
2561 b43_ntab_write(dev
, B43_NTAB16(8, 0), 2);
2562 b43_ntab_write(dev
, B43_NTAB16(8, 16), 2);
2566 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXA_MAST_BIAS
, 0x00);
2567 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXA_MAST_BIAS
, 0x00);
2568 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXA_BIAS_MAIN
, 0x06);
2569 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXA_BIAS_MAIN
, 0x06);
2570 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXA_BIAS_AUX
, 0x07);
2571 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXA_BIAS_AUX
, 0x07);
2572 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXA_LOB_BIAS
, 0x88);
2573 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXA_LOB_BIAS
, 0x88);
2574 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXA_CMFB_IDAC
, 0x00);
2575 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXA_CMFB_IDAC
, 0x00);
2576 b43_radio_write(dev
, B2056_RX0
| B2056_RX_MIXG_CMFB_IDAC
, 0x00);
2577 b43_radio_write(dev
, B2056_RX1
| B2056_RX_MIXG_CMFB_IDAC
, 0x00);
2579 /* N PHY WAR TX Chain Update with hw_phytxchain as argument */
2581 if ((sprom
->boardflags2_lo
& B43_BFL2_APLL_WAR
&&
2582 b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) ||
2583 (sprom
->boardflags2_lo
& B43_BFL2_GPLL_WAR
&&
2584 b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
))
2588 b43_ntab_write(dev
, B43_NTAB32(30, 1), tmp32
);
2589 b43_ntab_write(dev
, B43_NTAB32(30, 2), tmp32
);
2590 b43_ntab_write(dev
, B43_NTAB32(30, 3), tmp32
);
2592 if (dev
->phy
.rev
== 4 &&
2593 b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
2594 b43_radio_write(dev
, B2056_TX0
| B2056_TX_GMBB_IDAC
,
2596 b43_radio_write(dev
, B2056_TX1
| B2056_TX_GMBB_IDAC
,
2600 /* Dropped probably-always-true condition */
2601 b43_phy_write(dev
, B43_NPHY_ED_CRS40ASSERTTHRESH0
, 0x03eb);
2602 b43_phy_write(dev
, B43_NPHY_ED_CRS40ASSERTTHRESH1
, 0x03eb);
2603 b43_phy_write(dev
, B43_NPHY_ED_CRS40DEASSERTTHRESH1
, 0x0341);
2604 b43_phy_write(dev
, B43_NPHY_ED_CRS40DEASSERTTHRESH1
, 0x0341);
2605 b43_phy_write(dev
, B43_NPHY_ED_CRS20LASSERTTHRESH0
, 0x042b);
2606 b43_phy_write(dev
, B43_NPHY_ED_CRS20LASSERTTHRESH1
, 0x042b);
2607 b43_phy_write(dev
, B43_NPHY_ED_CRS20LDEASSERTTHRESH0
, 0x0381);
2608 b43_phy_write(dev
, B43_NPHY_ED_CRS20LDEASSERTTHRESH1
, 0x0381);
2609 b43_phy_write(dev
, B43_NPHY_ED_CRS20UASSERTTHRESH0
, 0x042b);
2610 b43_phy_write(dev
, B43_NPHY_ED_CRS20UASSERTTHRESH1
, 0x042b);
2611 b43_phy_write(dev
, B43_NPHY_ED_CRS20UDEASSERTTHRESH0
, 0x0381);
2612 b43_phy_write(dev
, B43_NPHY_ED_CRS20UDEASSERTTHRESH1
, 0x0381);
2614 if (dev
->phy
.rev
>= 6 && sprom
->boardflags2_lo
& B43_BFL2_SINGLEANT_CCK
)
2615 ; /* TODO: 0x0080000000000000 HF */
2618 static void b43_nphy_workarounds_rev1_2(struct b43_wldev
*dev
)
2620 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
2621 struct b43_phy
*phy
= &dev
->phy
;
2622 struct b43_phy_n
*nphy
= phy
->n
;
2624 u8 events1
[7] = { 0x0, 0x1, 0x2, 0x8, 0x4, 0x5, 0x3 };
2625 u8 delays1
[7] = { 0x8, 0x6, 0x6, 0x2, 0x4, 0x3C, 0x1 };
2627 u8 events2
[7] = { 0x0, 0x3, 0x5, 0x4, 0x2, 0x1, 0x8 };
2628 u8 delays2
[7] = { 0x8, 0x6, 0x2, 0x4, 0x4, 0x6, 0x1 };
2630 if (sprom
->boardflags2_lo
& B43_BFL2_SKWRKFEM_BRD
||
2631 dev
->dev
->board_type
== BCMA_BOARD_TYPE_BCM943224M93
) {
2636 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
&&
2637 nphy
->band5g_pwrgain
) {
2638 b43_radio_mask(dev
, B2055_C1_TX_RF_SPARE
, ~0x8);
2639 b43_radio_mask(dev
, B2055_C2_TX_RF_SPARE
, ~0x8);
2641 b43_radio_set(dev
, B2055_C1_TX_RF_SPARE
, 0x8);
2642 b43_radio_set(dev
, B2055_C2_TX_RF_SPARE
, 0x8);
2645 b43_ntab_write(dev
, B43_NTAB16(8, 0x00), 0x000A);
2646 b43_ntab_write(dev
, B43_NTAB16(8, 0x10), 0x000A);
2647 if (dev
->phy
.rev
< 3) {
2648 b43_ntab_write(dev
, B43_NTAB16(8, 0x02), 0xCDAA);
2649 b43_ntab_write(dev
, B43_NTAB16(8, 0x12), 0xCDAA);
2652 if (dev
->phy
.rev
< 2) {
2653 b43_ntab_write(dev
, B43_NTAB16(8, 0x08), 0x0000);
2654 b43_ntab_write(dev
, B43_NTAB16(8, 0x18), 0x0000);
2655 b43_ntab_write(dev
, B43_NTAB16(8, 0x07), 0x7AAB);
2656 b43_ntab_write(dev
, B43_NTAB16(8, 0x17), 0x7AAB);
2657 b43_ntab_write(dev
, B43_NTAB16(8, 0x06), 0x0800);
2658 b43_ntab_write(dev
, B43_NTAB16(8, 0x16), 0x0800);
2661 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_LO1
, 0x2D8);
2662 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP1
, 0x301);
2663 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_LO2
, 0x2D8);
2664 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP2
, 0x301);
2666 b43_nphy_set_rf_sequence(dev
, 0, events1
, delays1
, 7);
2667 b43_nphy_set_rf_sequence(dev
, 1, events2
, delays2
, 7);
2669 b43_nphy_gain_ctl_workarounds(dev
);
2671 if (dev
->phy
.rev
< 2) {
2672 if (b43_phy_read(dev
, B43_NPHY_RXCTL
) & 0x2)
2673 b43_hf_write(dev
, b43_hf_read(dev
) |
2675 } else if (dev
->phy
.rev
== 2) {
2676 b43_phy_write(dev
, B43_NPHY_CRSCHECK2
, 0);
2677 b43_phy_write(dev
, B43_NPHY_CRSCHECK3
, 0);
2680 if (dev
->phy
.rev
< 2)
2681 b43_phy_mask(dev
, B43_NPHY_SCRAM_SIGCTL
,
2682 ~B43_NPHY_SCRAM_SIGCTL_SCM
);
2684 /* Set phase track alpha and beta */
2685 b43_phy_write(dev
, B43_NPHY_PHASETR_A0
, 0x125);
2686 b43_phy_write(dev
, B43_NPHY_PHASETR_A1
, 0x1B3);
2687 b43_phy_write(dev
, B43_NPHY_PHASETR_A2
, 0x105);
2688 b43_phy_write(dev
, B43_NPHY_PHASETR_B0
, 0x16E);
2689 b43_phy_write(dev
, B43_NPHY_PHASETR_B1
, 0xCD);
2690 b43_phy_write(dev
, B43_NPHY_PHASETR_B2
, 0x20);
2692 if (dev
->phy
.rev
< 3) {
2693 b43_phy_mask(dev
, B43_NPHY_PIL_DW1
,
2694 ~B43_NPHY_PIL_DW_64QAM
& 0xFFFF);
2695 b43_phy_write(dev
, B43_NPHY_TXF_20CO_S2B1
, 0xB5);
2696 b43_phy_write(dev
, B43_NPHY_TXF_20CO_S2B2
, 0xA4);
2697 b43_phy_write(dev
, B43_NPHY_TXF_20CO_S2B3
, 0x00);
2700 if (dev
->phy
.rev
== 2)
2701 b43_phy_set(dev
, B43_NPHY_FINERX2_CGC
,
2702 B43_NPHY_FINERX2_CGC_DECGC
);
2705 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/Workarounds */
2706 static void b43_nphy_workarounds(struct b43_wldev
*dev
)
2708 struct b43_phy
*phy
= &dev
->phy
;
2709 struct b43_phy_n
*nphy
= phy
->n
;
2711 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
)
2712 b43_nphy_classifier(dev
, 1, 0);
2714 b43_nphy_classifier(dev
, 1, 1);
2716 if (nphy
->hang_avoid
)
2717 b43_nphy_stay_in_carrier_search(dev
, 1);
2719 b43_phy_set(dev
, B43_NPHY_IQFLIP
,
2720 B43_NPHY_IQFLIP_ADC1
| B43_NPHY_IQFLIP_ADC2
);
2722 if (dev
->phy
.rev
>= 7)
2723 b43_nphy_workarounds_rev7plus(dev
);
2724 else if (dev
->phy
.rev
>= 3)
2725 b43_nphy_workarounds_rev3plus(dev
);
2727 b43_nphy_workarounds_rev1_2(dev
);
2729 if (nphy
->hang_avoid
)
2730 b43_nphy_stay_in_carrier_search(dev
, 0);
2733 /**************************************************
2735 **************************************************/
2738 * Transmits a known value for LO calibration
2739 * http://bcm-v4.sipsolutions.net/802.11/PHY/N/TXTone
2741 static int b43_nphy_tx_tone(struct b43_wldev
*dev
, u32 freq
, u16 max_val
,
2742 bool iqmode
, bool dac_test
)
2744 u16 samp
= b43_nphy_gen_load_samples(dev
, freq
, max_val
, dac_test
);
2747 b43_nphy_run_samples(dev
, samp
, 0xFFFF, 0, iqmode
, dac_test
);
2751 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/Chains */
2752 static void b43_nphy_update_txrx_chain(struct b43_wldev
*dev
)
2754 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2756 bool override
= false;
2759 if (nphy
->txrx_chain
== 0) {
2762 } else if (nphy
->txrx_chain
== 1) {
2767 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
,
2768 ~(B43_NPHY_RFSEQCA_TXEN
| B43_NPHY_RFSEQCA_RXEN
),
2772 b43_phy_set(dev
, B43_NPHY_RFSEQMODE
,
2773 B43_NPHY_RFSEQMODE_CAOVER
);
2775 b43_phy_mask(dev
, B43_NPHY_RFSEQMODE
,
2776 ~B43_NPHY_RFSEQMODE_CAOVER
);
2779 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/stop-playback */
2780 static void b43_nphy_stop_playback(struct b43_wldev
*dev
)
2782 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2785 if (nphy
->hang_avoid
)
2786 b43_nphy_stay_in_carrier_search(dev
, 1);
2788 tmp
= b43_phy_read(dev
, B43_NPHY_SAMP_STAT
);
2790 b43_phy_set(dev
, B43_NPHY_SAMP_CMD
, B43_NPHY_SAMP_CMD_STOP
);
2792 b43_phy_mask(dev
, B43_NPHY_IQLOCAL_CMDGCTL
, 0x7FFF);
2794 b43_phy_mask(dev
, B43_NPHY_SAMP_CMD
, ~0x0004);
2796 if (nphy
->bb_mult_save
& 0x80000000) {
2797 tmp
= nphy
->bb_mult_save
& 0xFFFF;
2798 b43_ntab_write(dev
, B43_NTAB16(15, 87), tmp
);
2799 nphy
->bb_mult_save
= 0;
2802 if (nphy
->hang_avoid
)
2803 b43_nphy_stay_in_carrier_search(dev
, 0);
2806 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/IqCalGainParams */
2807 static void b43_nphy_iq_cal_gain_params(struct b43_wldev
*dev
, u16 core
,
2808 struct nphy_txgains target
,
2809 struct nphy_iqcal_params
*params
)
2814 if (dev
->phy
.rev
>= 3) {
2815 params
->txgm
= target
.txgm
[core
];
2816 params
->pga
= target
.pga
[core
];
2817 params
->pad
= target
.pad
[core
];
2818 params
->ipa
= target
.ipa
[core
];
2819 params
->cal_gain
= (params
->txgm
<< 12) | (params
->pga
<< 8) |
2820 (params
->pad
<< 4) | (params
->ipa
);
2821 for (j
= 0; j
< 5; j
++)
2822 params
->ncorr
[j
] = 0x79;
2824 gain
= (target
.pad
[core
]) | (target
.pga
[core
] << 4) |
2825 (target
.txgm
[core
] << 8);
2827 indx
= (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) ?
2829 for (i
= 0; i
< 9; i
++)
2830 if (tbl_iqcal_gainparams
[indx
][i
][0] == gain
)
2834 params
->txgm
= tbl_iqcal_gainparams
[indx
][i
][1];
2835 params
->pga
= tbl_iqcal_gainparams
[indx
][i
][2];
2836 params
->pad
= tbl_iqcal_gainparams
[indx
][i
][3];
2837 params
->cal_gain
= (params
->txgm
<< 7) | (params
->pga
<< 4) |
2839 for (j
= 0; j
< 4; j
++)
2840 params
->ncorr
[j
] = tbl_iqcal_gainparams
[indx
][i
][4 + j
];
2844 /**************************************************
2846 **************************************************/
2848 static void b43_nphy_op_adjust_txpower(struct b43_wldev
*dev
)
2852 static enum b43_txpwr_result
b43_nphy_op_recalc_txpower(struct b43_wldev
*dev
,
2855 return B43_TXPWR_RES_DONE
;
2858 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlEnable */
2859 static void b43_nphy_tx_power_ctrl(struct b43_wldev
*dev
, bool enable
)
2861 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2863 u16 bmask
, val
, tmp
;
2864 enum ieee80211_band band
= b43_current_band(dev
->wl
);
2866 if (nphy
->hang_avoid
)
2867 b43_nphy_stay_in_carrier_search(dev
, 1);
2869 nphy
->txpwrctrl
= enable
;
2871 if (dev
->phy
.rev
>= 3 &&
2872 (b43_phy_read(dev
, B43_NPHY_TXPCTL_CMD
) &
2873 (B43_NPHY_TXPCTL_CMD_COEFF
|
2874 B43_NPHY_TXPCTL_CMD_HWPCTLEN
|
2875 B43_NPHY_TXPCTL_CMD_PCTLEN
))) {
2876 /* We disable enabled TX pwr ctl, save it's state */
2877 nphy
->tx_pwr_idx
[0] = b43_phy_read(dev
,
2878 B43_NPHY_C1_TXPCTL_STAT
) & 0x7f;
2879 nphy
->tx_pwr_idx
[1] = b43_phy_read(dev
,
2880 B43_NPHY_C2_TXPCTL_STAT
) & 0x7f;
2883 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x6840);
2884 for (i
= 0; i
< 84; i
++)
2885 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0);
2887 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
, 0x6C40);
2888 for (i
= 0; i
< 84; i
++)
2889 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
, 0);
2891 tmp
= B43_NPHY_TXPCTL_CMD_COEFF
| B43_NPHY_TXPCTL_CMD_HWPCTLEN
;
2892 if (dev
->phy
.rev
>= 3)
2893 tmp
|= B43_NPHY_TXPCTL_CMD_PCTLEN
;
2894 b43_phy_mask(dev
, B43_NPHY_TXPCTL_CMD
, ~tmp
);
2896 if (dev
->phy
.rev
>= 3) {
2897 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER1
, 0x0100);
2898 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x0100);
2900 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x4000);
2903 if (dev
->phy
.rev
== 2)
2904 b43_phy_maskset(dev
, B43_NPHY_BPHY_CTL3
,
2905 ~B43_NPHY_BPHY_CTL3_SCALE
, 0x53);
2906 else if (dev
->phy
.rev
< 2)
2907 b43_phy_maskset(dev
, B43_NPHY_BPHY_CTL3
,
2908 ~B43_NPHY_BPHY_CTL3_SCALE
, 0x5A);
2910 if (dev
->phy
.rev
< 2 && dev
->phy
.is_40mhz
)
2911 b43_hf_write(dev
, b43_hf_read(dev
) | B43_HF_TSSIRPSMW
);
2913 b43_ntab_write_bulk(dev
, B43_NTAB16(26, 64), 84,
2915 b43_ntab_write_bulk(dev
, B43_NTAB16(27, 64), 84,
2918 bmask
= B43_NPHY_TXPCTL_CMD_COEFF
|
2919 B43_NPHY_TXPCTL_CMD_HWPCTLEN
;
2920 /* wl does useless check for "enable" param here */
2921 val
= B43_NPHY_TXPCTL_CMD_COEFF
| B43_NPHY_TXPCTL_CMD_HWPCTLEN
;
2922 if (dev
->phy
.rev
>= 3) {
2923 bmask
|= B43_NPHY_TXPCTL_CMD_PCTLEN
;
2925 val
|= B43_NPHY_TXPCTL_CMD_PCTLEN
;
2927 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_CMD
, ~(bmask
), val
);
2929 if (band
== IEEE80211_BAND_5GHZ
) {
2930 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_CMD
,
2931 ~B43_NPHY_TXPCTL_CMD_INIT
, 0x64);
2932 if (dev
->phy
.rev
> 1)
2933 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_INIT
,
2934 ~B43_NPHY_TXPCTL_INIT_PIDXI1
,
2938 if (dev
->phy
.rev
>= 3) {
2939 if (nphy
->tx_pwr_idx
[0] != 128 &&
2940 nphy
->tx_pwr_idx
[1] != 128) {
2941 /* Recover TX pwr ctl state */
2942 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_CMD
,
2943 ~B43_NPHY_TXPCTL_CMD_INIT
,
2944 nphy
->tx_pwr_idx
[0]);
2945 if (dev
->phy
.rev
> 1)
2946 b43_phy_maskset(dev
,
2947 B43_NPHY_TXPCTL_INIT
,
2948 ~0xff, nphy
->tx_pwr_idx
[1]);
2952 if (dev
->phy
.rev
>= 3) {
2953 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER1
, ~0x100);
2954 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER
, ~0x100);
2956 b43_phy_mask(dev
, B43_NPHY_AFECTL_OVER
, ~0x4000);
2959 if (dev
->phy
.rev
== 2)
2960 b43_phy_maskset(dev
, B43_NPHY_BPHY_CTL3
, ~0xFF, 0x3b);
2961 else if (dev
->phy
.rev
< 2)
2962 b43_phy_maskset(dev
, B43_NPHY_BPHY_CTL3
, ~0xFF, 0x40);
2964 if (dev
->phy
.rev
< 2 && dev
->phy
.is_40mhz
)
2965 b43_hf_write(dev
, b43_hf_read(dev
) & ~B43_HF_TSSIRPSMW
);
2967 if (b43_nphy_ipa(dev
)) {
2968 b43_phy_mask(dev
, B43_NPHY_PAPD_EN0
, ~0x4);
2969 b43_phy_mask(dev
, B43_NPHY_PAPD_EN1
, ~0x4);
2973 if (nphy
->hang_avoid
)
2974 b43_nphy_stay_in_carrier_search(dev
, 0);
2977 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrFix */
2978 static void b43_nphy_tx_power_fix(struct b43_wldev
*dev
)
2980 struct b43_phy_n
*nphy
= dev
->phy
.n
;
2981 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
2983 u8 txpi
[2], bbmult
, i
;
2984 u16 tmp
, radio_gain
, dac_gain
;
2985 u16 freq
= dev
->phy
.channel_freq
;
2987 /* u32 gaintbl; rev3+ */
2989 if (nphy
->hang_avoid
)
2990 b43_nphy_stay_in_carrier_search(dev
, 1);
2992 if (dev
->phy
.rev
>= 7) {
2993 txpi
[0] = txpi
[1] = 30;
2994 } else if (dev
->phy
.rev
>= 3) {
2997 } else if (sprom
->revision
< 4) {
3001 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
3002 txpi
[0] = sprom
->txpid2g
[0];
3003 txpi
[1] = sprom
->txpid2g
[1];
3004 } else if (freq
>= 4900 && freq
< 5100) {
3005 txpi
[0] = sprom
->txpid5gl
[0];
3006 txpi
[1] = sprom
->txpid5gl
[1];
3007 } else if (freq
>= 5100 && freq
< 5500) {
3008 txpi
[0] = sprom
->txpid5g
[0];
3009 txpi
[1] = sprom
->txpid5g
[1];
3010 } else if (freq
>= 5500) {
3011 txpi
[0] = sprom
->txpid5gh
[0];
3012 txpi
[1] = sprom
->txpid5gh
[1];
3018 if (dev
->phy
.rev
< 7 &&
3019 (txpi
[0] < 40 || txpi
[0] > 100 || txpi
[1] < 40 || txpi
[1] > 100))
3020 txpi
[0] = txpi
[1] = 91;
3023 for (i = 0; i < 2; i++) {
3024 nphy->txpwrindex[i].index_internal = txpi[i];
3025 nphy->txpwrindex[i].index_internal_save = txpi[i];
3029 for (i
= 0; i
< 2; i
++) {
3030 txgain
= *(b43_nphy_get_tx_gain_table(dev
) + txpi
[i
]);
3032 if (dev
->phy
.rev
>= 3)
3033 radio_gain
= (txgain
>> 16) & 0x1FFFF;
3035 radio_gain
= (txgain
>> 16) & 0x1FFF;
3037 if (dev
->phy
.rev
>= 7)
3038 dac_gain
= (txgain
>> 8) & 0x7;
3040 dac_gain
= (txgain
>> 8) & 0x3F;
3041 bbmult
= txgain
& 0xFF;
3043 if (dev
->phy
.rev
>= 3) {
3045 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER1
, 0x0100);
3047 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x0100);
3049 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x4000);
3053 b43_phy_write(dev
, B43_NPHY_AFECTL_DACGAIN1
, dac_gain
);
3055 b43_phy_write(dev
, B43_NPHY_AFECTL_DACGAIN2
, dac_gain
);
3057 b43_ntab_write(dev
, B43_NTAB16(0x7, 0x110 + i
), radio_gain
);
3059 tmp
= b43_ntab_read(dev
, B43_NTAB16(0xF, 0x57));
3061 tmp
= (tmp
& 0x00FF) | (bbmult
<< 8);
3063 tmp
= (tmp
& 0xFF00) | bbmult
;
3064 b43_ntab_write(dev
, B43_NTAB16(0xF, 0x57), tmp
);
3066 if (b43_nphy_ipa(dev
)) {
3068 u16 reg
= (i
== 0) ?
3069 B43_NPHY_PAPD_EN0
: B43_NPHY_PAPD_EN1
;
3070 tmp32
= b43_ntab_read(dev
, B43_NTAB32(26 + i
,
3072 b43_phy_maskset(dev
, reg
, 0xE00F, (u32
) tmp32
<< 4);
3073 b43_phy_set(dev
, reg
, 0x4);
3077 b43_phy_mask(dev
, B43_NPHY_BPHY_CTL2
, ~B43_NPHY_BPHY_CTL2_LUT
);
3079 if (nphy
->hang_avoid
)
3080 b43_nphy_stay_in_carrier_search(dev
, 0);
3083 static void b43_nphy_ipa_internal_tssi_setup(struct b43_wldev
*dev
)
3085 struct b43_phy
*phy
= &dev
->phy
;
3088 u16 r
; /* routing */
3090 if (phy
->rev
>= 7) {
3091 for (core
= 0; core
< 2; core
++) {
3092 r
= core
? 0x190 : 0x170;
3093 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
3094 b43_radio_write(dev
, r
+ 0x5, 0x5);
3095 b43_radio_write(dev
, r
+ 0x9, 0xE);
3097 b43_radio_write(dev
, r
+ 0xA, 0);
3099 b43_radio_write(dev
, r
+ 0xB, 1);
3101 b43_radio_write(dev
, r
+ 0xB, 0x31);
3103 b43_radio_write(dev
, r
+ 0x5, 0x9);
3104 b43_radio_write(dev
, r
+ 0x9, 0xC);
3105 b43_radio_write(dev
, r
+ 0xB, 0x0);
3107 b43_radio_write(dev
, r
+ 0xA, 1);
3109 b43_radio_write(dev
, r
+ 0xA, 0x31);
3111 b43_radio_write(dev
, r
+ 0x6, 0);
3112 b43_radio_write(dev
, r
+ 0x7, 0);
3113 b43_radio_write(dev
, r
+ 0x8, 3);
3114 b43_radio_write(dev
, r
+ 0xC, 0);
3117 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
3118 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR31
, 0x128);
3120 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR31
, 0x80);
3121 b43_radio_write(dev
, B2056_SYN_RESERVED_ADDR30
, 0);
3122 b43_radio_write(dev
, B2056_SYN_GPIO_MASTER1
, 0x29);
3124 for (core
= 0; core
< 2; core
++) {
3125 r
= core
? B2056_TX1
: B2056_TX0
;
3127 b43_radio_write(dev
, r
| B2056_TX_IQCAL_VCM_HG
, 0);
3128 b43_radio_write(dev
, r
| B2056_TX_IQCAL_IDAC
, 0);
3129 b43_radio_write(dev
, r
| B2056_TX_TSSI_VCM
, 3);
3130 b43_radio_write(dev
, r
| B2056_TX_TX_AMP_DET
, 0);
3131 b43_radio_write(dev
, r
| B2056_TX_TSSI_MISC1
, 8);
3132 b43_radio_write(dev
, r
| B2056_TX_TSSI_MISC2
, 0);
3133 b43_radio_write(dev
, r
| B2056_TX_TSSI_MISC3
, 0);
3134 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
3135 b43_radio_write(dev
, r
| B2056_TX_TX_SSI_MASTER
,
3138 b43_radio_write(dev
, r
| B2056_TX_TSSIA
,
3141 b43_radio_write(dev
, r
| B2056_TX_TSSIG
,
3144 b43_radio_write(dev
, r
| B2056_TX_TSSIG
,
3146 b43_radio_write(dev
, r
| B2056_TX_TX_SSI_MUX
,
3149 b43_radio_write(dev
, r
| B2056_TX_TX_SSI_MASTER
,
3151 b43_radio_write(dev
, r
| B2056_TX_TSSIA
, 0x31);
3152 b43_radio_write(dev
, r
| B2056_TX_TSSIG
, 0x0);
3153 b43_radio_write(dev
, r
| B2056_TX_TX_SSI_MUX
,
3161 * Stop radio and transmit known signal. Then check received signal strength to
3162 * get TSSI (Transmit Signal Strength Indicator).
3163 * http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlIdleTssi
3165 static void b43_nphy_tx_power_ctl_idle_tssi(struct b43_wldev
*dev
)
3167 struct b43_phy
*phy
= &dev
->phy
;
3168 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3173 /* TODO: check if we can transmit */
3175 if (b43_nphy_ipa(dev
))
3176 b43_nphy_ipa_internal_tssi_setup(dev
);
3179 b43_nphy_rf_ctl_override_rev7(dev
, 0x2000, 0, 3, false, 0);
3180 else if (phy
->rev
>= 3)
3181 b43_nphy_rf_ctl_override(dev
, 0x2000, 0, 3, false);
3183 b43_nphy_stop_playback(dev
);
3184 b43_nphy_tx_tone(dev
, 0xFA0, 0, false, false);
3186 tmp
= b43_nphy_poll_rssi(dev
, N_RSSI_TSSI_2G
, rssi
, 1);
3187 b43_nphy_stop_playback(dev
);
3188 b43_nphy_rssi_select(dev
, 0, N_RSSI_W1
);
3191 b43_nphy_rf_ctl_override_rev7(dev
, 0x2000, 0, 3, true, 0);
3192 else if (phy
->rev
>= 3)
3193 b43_nphy_rf_ctl_override(dev
, 0x2000, 0, 3, true);
3195 if (phy
->rev
>= 3) {
3196 nphy
->pwr_ctl_info
[0].idle_tssi_5g
= (tmp
>> 24) & 0xFF;
3197 nphy
->pwr_ctl_info
[1].idle_tssi_5g
= (tmp
>> 8) & 0xFF;
3199 nphy
->pwr_ctl_info
[0].idle_tssi_5g
= (tmp
>> 16) & 0xFF;
3200 nphy
->pwr_ctl_info
[1].idle_tssi_5g
= tmp
& 0xFF;
3202 nphy
->pwr_ctl_info
[0].idle_tssi_2g
= (tmp
>> 24) & 0xFF;
3203 nphy
->pwr_ctl_info
[1].idle_tssi_2g
= (tmp
>> 8) & 0xFF;
3206 /* http://bcm-v4.sipsolutions.net/PHY/N/TxPwrLimitToTbl */
3207 static void b43_nphy_tx_prepare_adjusted_power_table(struct b43_wldev
*dev
)
3209 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3214 for (i
= 0; i
< 4; i
++)
3215 nphy
->adj_pwr_tbl
[i
] = nphy
->tx_power_offset
[i
];
3217 for (stf_mode
= 0; stf_mode
< 4; stf_mode
++) {
3221 if (dev
->phy
.is_40mhz
&& dev
->phy
.rev
>= 5) {
3225 idx
= dev
->phy
.is_40mhz
? 52 : 4;
3229 idx
= dev
->phy
.is_40mhz
? 76 : 28;
3232 idx
= dev
->phy
.is_40mhz
? 84 : 36;
3235 idx
= dev
->phy
.is_40mhz
? 92 : 44;
3239 for (i
= 0; i
< 20; i
++) {
3240 nphy
->adj_pwr_tbl
[4 + 4 * i
+ stf_mode
] =
3241 nphy
->tx_power_offset
[idx
];
3246 if (i
== 3 || i
== 4 || i
== 7 || i
== 8 || i
== 11 ||
3253 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlSetup */
3254 static void b43_nphy_tx_power_ctl_setup(struct b43_wldev
*dev
)
3256 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3257 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
3259 s16 a1
[2], b0
[2], b1
[2];
3265 u16 freq
= dev
->phy
.channel_freq
;
3267 u16 r
; /* routing */
3270 if (dev
->dev
->core_rev
== 11 || dev
->dev
->core_rev
== 12) {
3271 b43_maskset32(dev
, B43_MMIO_MACCTL
, ~0, 0x200000);
3272 b43_read32(dev
, B43_MMIO_MACCTL
);
3276 if (nphy
->hang_avoid
)
3277 b43_nphy_stay_in_carrier_search(dev
, true);
3279 b43_phy_set(dev
, B43_NPHY_TSSIMODE
, B43_NPHY_TSSIMODE_EN
);
3280 if (dev
->phy
.rev
>= 3)
3281 b43_phy_mask(dev
, B43_NPHY_TXPCTL_CMD
,
3282 ~B43_NPHY_TXPCTL_CMD_PCTLEN
& 0xFFFF);
3284 b43_phy_set(dev
, B43_NPHY_TXPCTL_CMD
,
3285 B43_NPHY_TXPCTL_CMD_PCTLEN
);
3287 if (dev
->dev
->core_rev
== 11 || dev
->dev
->core_rev
== 12)
3288 b43_maskset32(dev
, B43_MMIO_MACCTL
, ~0x200000, 0);
3290 if (sprom
->revision
< 4) {
3291 idle
[0] = nphy
->pwr_ctl_info
[0].idle_tssi_2g
;
3292 idle
[1] = nphy
->pwr_ctl_info
[1].idle_tssi_2g
;
3293 target
[0] = target
[1] = 52;
3294 a1
[0] = a1
[1] = -424;
3295 b0
[0] = b0
[1] = 5612;
3296 b1
[0] = b1
[1] = -1393;
3298 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
3299 for (c
= 0; c
< 2; c
++) {
3300 idle
[c
] = nphy
->pwr_ctl_info
[c
].idle_tssi_2g
;
3301 target
[c
] = sprom
->core_pwr_info
[c
].maxpwr_2g
;
3302 a1
[c
] = sprom
->core_pwr_info
[c
].pa_2g
[0];
3303 b0
[c
] = sprom
->core_pwr_info
[c
].pa_2g
[1];
3304 b1
[c
] = sprom
->core_pwr_info
[c
].pa_2g
[2];
3306 } else if (freq
>= 4900 && freq
< 5100) {
3307 for (c
= 0; c
< 2; c
++) {
3308 idle
[c
] = nphy
->pwr_ctl_info
[c
].idle_tssi_5g
;
3309 target
[c
] = sprom
->core_pwr_info
[c
].maxpwr_5gl
;
3310 a1
[c
] = sprom
->core_pwr_info
[c
].pa_5gl
[0];
3311 b0
[c
] = sprom
->core_pwr_info
[c
].pa_5gl
[1];
3312 b1
[c
] = sprom
->core_pwr_info
[c
].pa_5gl
[2];
3314 } else if (freq
>= 5100 && freq
< 5500) {
3315 for (c
= 0; c
< 2; c
++) {
3316 idle
[c
] = nphy
->pwr_ctl_info
[c
].idle_tssi_5g
;
3317 target
[c
] = sprom
->core_pwr_info
[c
].maxpwr_5g
;
3318 a1
[c
] = sprom
->core_pwr_info
[c
].pa_5g
[0];
3319 b0
[c
] = sprom
->core_pwr_info
[c
].pa_5g
[1];
3320 b1
[c
] = sprom
->core_pwr_info
[c
].pa_5g
[2];
3322 } else if (freq
>= 5500) {
3323 for (c
= 0; c
< 2; c
++) {
3324 idle
[c
] = nphy
->pwr_ctl_info
[c
].idle_tssi_5g
;
3325 target
[c
] = sprom
->core_pwr_info
[c
].maxpwr_5gh
;
3326 a1
[c
] = sprom
->core_pwr_info
[c
].pa_5gh
[0];
3327 b0
[c
] = sprom
->core_pwr_info
[c
].pa_5gh
[1];
3328 b1
[c
] = sprom
->core_pwr_info
[c
].pa_5gh
[2];
3331 idle
[0] = nphy
->pwr_ctl_info
[0].idle_tssi_5g
;
3332 idle
[1] = nphy
->pwr_ctl_info
[1].idle_tssi_5g
;
3333 target
[0] = target
[1] = 52;
3334 a1
[0] = a1
[1] = -424;
3335 b0
[0] = b0
[1] = 5612;
3336 b1
[0] = b1
[1] = -1393;
3339 /* target[0] = target[1] = nphy->tx_power_max; */
3341 if (dev
->phy
.rev
>= 3) {
3342 if (sprom
->fem
.ghz2
.tssipos
)
3343 b43_phy_set(dev
, B43_NPHY_TXPCTL_ITSSI
, 0x4000);
3344 if (dev
->phy
.rev
>= 7) {
3345 for (c
= 0; c
< 2; c
++) {
3346 r
= c
? 0x190 : 0x170;
3347 if (b43_nphy_ipa(dev
))
3348 b43_radio_write(dev
, r
+ 0x9, (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) ? 0xE : 0xC);
3351 if (b43_nphy_ipa(dev
)) {
3352 tmp
= (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) ? 0xC : 0xE;
3353 b43_radio_write(dev
,
3354 B2056_TX0
| B2056_TX_TX_SSI_MUX
, tmp
);
3355 b43_radio_write(dev
,
3356 B2056_TX1
| B2056_TX_TX_SSI_MUX
, tmp
);
3358 b43_radio_write(dev
,
3359 B2056_TX0
| B2056_TX_TX_SSI_MUX
, 0x11);
3360 b43_radio_write(dev
,
3361 B2056_TX1
| B2056_TX_TX_SSI_MUX
, 0x11);
3366 if (dev
->dev
->core_rev
== 11 || dev
->dev
->core_rev
== 12) {
3367 b43_maskset32(dev
, B43_MMIO_MACCTL
, ~0, 0x200000);
3368 b43_read32(dev
, B43_MMIO_MACCTL
);
3372 if (dev
->phy
.rev
>= 7) {
3373 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_CMD
,
3374 ~B43_NPHY_TXPCTL_CMD_INIT
, 0x19);
3375 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_INIT
,
3376 ~B43_NPHY_TXPCTL_INIT_PIDXI1
, 0x19);
3378 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_CMD
,
3379 ~B43_NPHY_TXPCTL_CMD_INIT
, 0x40);
3380 if (dev
->phy
.rev
> 1)
3381 b43_phy_maskset(dev
, B43_NPHY_TXPCTL_INIT
,
3382 ~B43_NPHY_TXPCTL_INIT_PIDXI1
, 0x40);
3385 if (dev
->dev
->core_rev
== 11 || dev
->dev
->core_rev
== 12)
3386 b43_maskset32(dev
, B43_MMIO_MACCTL
, ~0x200000, 0);
3388 b43_phy_write(dev
, B43_NPHY_TXPCTL_N
,
3389 0xF0 << B43_NPHY_TXPCTL_N_TSSID_SHIFT
|
3390 3 << B43_NPHY_TXPCTL_N_NPTIL2_SHIFT
);
3391 b43_phy_write(dev
, B43_NPHY_TXPCTL_ITSSI
,
3392 idle
[0] << B43_NPHY_TXPCTL_ITSSI_0_SHIFT
|
3393 idle
[1] << B43_NPHY_TXPCTL_ITSSI_1_SHIFT
|
3394 B43_NPHY_TXPCTL_ITSSI_BINF
);
3395 b43_phy_write(dev
, B43_NPHY_TXPCTL_TPWR
,
3396 target
[0] << B43_NPHY_TXPCTL_TPWR_0_SHIFT
|
3397 target
[1] << B43_NPHY_TXPCTL_TPWR_1_SHIFT
);
3399 for (c
= 0; c
< 2; c
++) {
3400 for (i
= 0; i
< 64; i
++) {
3401 num
= 8 * (16 * b0
[c
] + b1
[c
] * i
);
3402 den
= 32768 + a1
[c
] * i
;
3403 pwr
= max((4 * num
+ den
/ 2) / den
, -8);
3404 if (dev
->phy
.rev
< 3 && (i
<= (31 - idle
[c
] + 1)))
3405 pwr
= max(pwr
, target
[c
] + 1);
3408 b43_ntab_write_bulk(dev
, B43_NTAB32(26 + c
, 0), 64, regval
);
3411 b43_nphy_tx_prepare_adjusted_power_table(dev
);
3413 b43_ntab_write_bulk(dev, B43_NTAB16(26, 64), 84, nphy->adj_pwr_tbl);
3414 b43_ntab_write_bulk(dev, B43_NTAB16(27, 64), 84, nphy->adj_pwr_tbl);
3417 if (nphy
->hang_avoid
)
3418 b43_nphy_stay_in_carrier_search(dev
, false);
3421 static void b43_nphy_tx_gain_table_upload(struct b43_wldev
*dev
)
3423 struct b43_phy
*phy
= &dev
->phy
;
3425 const u32
*table
= NULL
;
3430 table
= b43_nphy_get_tx_gain_table(dev
);
3431 b43_ntab_write_bulk(dev
, B43_NTAB32(26, 192), 128, table
);
3432 b43_ntab_write_bulk(dev
, B43_NTAB32(27, 192), 128, table
);
3434 if (phy
->rev
>= 3) {
3436 nphy
->gmval
= (table
[0] >> 16) & 0x7000;
3439 for (i
= 0; i
< 128; i
++) {
3440 pga_gain
= (table
[i
] >> 24) & 0xF;
3441 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
3443 b43_ntab_papd_pga_gain_delta_ipa_2g
[pga_gain
];
3447 b43_ntab_write(dev
, B43_NTAB32(26, 576 + i
),
3449 b43_ntab_write(dev
, B43_NTAB32(27, 576 + i
),
3455 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/PA%20override */
3456 static void b43_nphy_pa_override(struct b43_wldev
*dev
, bool enable
)
3458 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3459 enum ieee80211_band band
;
3463 nphy
->rfctrl_intc1_save
= b43_phy_read(dev
,
3464 B43_NPHY_RFCTL_INTC1
);
3465 nphy
->rfctrl_intc2_save
= b43_phy_read(dev
,
3466 B43_NPHY_RFCTL_INTC2
);
3467 band
= b43_current_band(dev
->wl
);
3468 if (dev
->phy
.rev
>= 3) {
3469 if (band
== IEEE80211_BAND_5GHZ
)
3474 if (band
== IEEE80211_BAND_5GHZ
)
3479 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, tmp
);
3480 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, tmp
);
3482 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
,
3483 nphy
->rfctrl_intc1_save
);
3484 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
,
3485 nphy
->rfctrl_intc2_save
);
3489 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxLpFbw */
3490 static void b43_nphy_tx_lp_fbw(struct b43_wldev
*dev
)
3494 if (dev
->phy
.rev
>= 3) {
3495 if (b43_nphy_ipa(dev
)) {
3497 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B32S2
,
3498 (((((tmp
<< 3) | tmp
) << 3) | tmp
) << 3) | tmp
);
3502 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B1S2
,
3503 (((((tmp
<< 3) | tmp
) << 3) | tmp
) << 3) | tmp
);
3507 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxIqEst */
3508 static void b43_nphy_rx_iq_est(struct b43_wldev
*dev
, struct nphy_iq_est
*est
,
3509 u16 samps
, u8 time
, bool wait
)
3514 b43_phy_write(dev
, B43_NPHY_IQEST_SAMCNT
, samps
);
3515 b43_phy_maskset(dev
, B43_NPHY_IQEST_WT
, ~B43_NPHY_IQEST_WT_VAL
, time
);
3517 b43_phy_set(dev
, B43_NPHY_IQEST_CMD
, B43_NPHY_IQEST_CMD_MODE
);
3519 b43_phy_mask(dev
, B43_NPHY_IQEST_CMD
, ~B43_NPHY_IQEST_CMD_MODE
);
3521 b43_phy_set(dev
, B43_NPHY_IQEST_CMD
, B43_NPHY_IQEST_CMD_START
);
3523 for (i
= 1000; i
; i
--) {
3524 tmp
= b43_phy_read(dev
, B43_NPHY_IQEST_CMD
);
3525 if (!(tmp
& B43_NPHY_IQEST_CMD_START
)) {
3526 est
->i0_pwr
= (b43_phy_read(dev
, B43_NPHY_IQEST_IPACC_HI0
) << 16) |
3527 b43_phy_read(dev
, B43_NPHY_IQEST_IPACC_LO0
);
3528 est
->q0_pwr
= (b43_phy_read(dev
, B43_NPHY_IQEST_QPACC_HI0
) << 16) |
3529 b43_phy_read(dev
, B43_NPHY_IQEST_QPACC_LO0
);
3530 est
->iq0_prod
= (b43_phy_read(dev
, B43_NPHY_IQEST_IQACC_HI0
) << 16) |
3531 b43_phy_read(dev
, B43_NPHY_IQEST_IQACC_LO0
);
3533 est
->i1_pwr
= (b43_phy_read(dev
, B43_NPHY_IQEST_IPACC_HI1
) << 16) |
3534 b43_phy_read(dev
, B43_NPHY_IQEST_IPACC_LO1
);
3535 est
->q1_pwr
= (b43_phy_read(dev
, B43_NPHY_IQEST_QPACC_HI1
) << 16) |
3536 b43_phy_read(dev
, B43_NPHY_IQEST_QPACC_LO1
);
3537 est
->iq1_prod
= (b43_phy_read(dev
, B43_NPHY_IQEST_IQACC_HI1
) << 16) |
3538 b43_phy_read(dev
, B43_NPHY_IQEST_IQACC_LO1
);
3543 memset(est
, 0, sizeof(*est
));
3546 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxIqCoeffs */
3547 static void b43_nphy_rx_iq_coeffs(struct b43_wldev
*dev
, bool write
,
3548 struct b43_phy_n_iq_comp
*pcomp
)
3551 b43_phy_write(dev
, B43_NPHY_C1_RXIQ_COMPA0
, pcomp
->a0
);
3552 b43_phy_write(dev
, B43_NPHY_C1_RXIQ_COMPB0
, pcomp
->b0
);
3553 b43_phy_write(dev
, B43_NPHY_C2_RXIQ_COMPA1
, pcomp
->a1
);
3554 b43_phy_write(dev
, B43_NPHY_C2_RXIQ_COMPB1
, pcomp
->b1
);
3556 pcomp
->a0
= b43_phy_read(dev
, B43_NPHY_C1_RXIQ_COMPA0
);
3557 pcomp
->b0
= b43_phy_read(dev
, B43_NPHY_C1_RXIQ_COMPB0
);
3558 pcomp
->a1
= b43_phy_read(dev
, B43_NPHY_C2_RXIQ_COMPA1
);
3559 pcomp
->b1
= b43_phy_read(dev
, B43_NPHY_C2_RXIQ_COMPB1
);
3564 /* Ready but not used anywhere */
3565 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCalPhyCleanup */
3566 static void b43_nphy_rx_cal_phy_cleanup(struct b43_wldev
*dev
, u8 core
)
3568 u16
*regs
= dev
->phy
.n
->tx_rx_cal_phy_saveregs
;
3570 b43_phy_write(dev
, B43_NPHY_RFSEQCA
, regs
[0]);
3572 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, regs
[1]);
3573 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, regs
[2]);
3575 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, regs
[1]);
3576 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, regs
[2]);
3578 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, regs
[3]);
3579 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, regs
[4]);
3580 b43_phy_write(dev
, B43_NPHY_RFCTL_RSSIO1
, regs
[5]);
3581 b43_phy_write(dev
, B43_NPHY_RFCTL_RSSIO2
, regs
[6]);
3582 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B1S1
, regs
[7]);
3583 b43_phy_write(dev
, B43_NPHY_RFCTL_OVER
, regs
[8]);
3584 b43_phy_write(dev
, B43_NPHY_PAPD_EN0
, regs
[9]);
3585 b43_phy_write(dev
, B43_NPHY_PAPD_EN1
, regs
[10]);
3588 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCalPhySetup */
3589 static void b43_nphy_rx_cal_phy_setup(struct b43_wldev
*dev
, u8 core
)
3592 u16
*regs
= dev
->phy
.n
->tx_rx_cal_phy_saveregs
;
3594 regs
[0] = b43_phy_read(dev
, B43_NPHY_RFSEQCA
);
3596 regs
[1] = b43_phy_read(dev
, B43_NPHY_AFECTL_C1
);
3597 regs
[2] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER1
);
3599 regs
[1] = b43_phy_read(dev
, B43_NPHY_AFECTL_C2
);
3600 regs
[2] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
3602 regs
[3] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC1
);
3603 regs
[4] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC2
);
3604 regs
[5] = b43_phy_read(dev
, B43_NPHY_RFCTL_RSSIO1
);
3605 regs
[6] = b43_phy_read(dev
, B43_NPHY_RFCTL_RSSIO2
);
3606 regs
[7] = b43_phy_read(dev
, B43_NPHY_TXF_40CO_B1S1
);
3607 regs
[8] = b43_phy_read(dev
, B43_NPHY_RFCTL_OVER
);
3608 regs
[9] = b43_phy_read(dev
, B43_NPHY_PAPD_EN0
);
3609 regs
[10] = b43_phy_read(dev
, B43_NPHY_PAPD_EN1
);
3611 b43_phy_mask(dev
, B43_NPHY_PAPD_EN0
, ~0x0001);
3612 b43_phy_mask(dev
, B43_NPHY_PAPD_EN1
, ~0x0001);
3614 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
,
3615 ~B43_NPHY_RFSEQCA_RXDIS
& 0xFFFF,
3616 ((1 - core
) << B43_NPHY_RFSEQCA_RXDIS_SHIFT
));
3617 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
, ~B43_NPHY_RFSEQCA_TXEN
,
3618 ((1 - core
) << B43_NPHY_RFSEQCA_TXEN_SHIFT
));
3619 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
, ~B43_NPHY_RFSEQCA_RXEN
,
3620 (core
<< B43_NPHY_RFSEQCA_RXEN_SHIFT
));
3621 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
, ~B43_NPHY_RFSEQCA_TXDIS
,
3622 (core
<< B43_NPHY_RFSEQCA_TXDIS_SHIFT
));
3625 b43_phy_mask(dev
, B43_NPHY_AFECTL_C1
, ~0x0007);
3626 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER1
, 0x0007);
3628 b43_phy_mask(dev
, B43_NPHY_AFECTL_C2
, ~0x0007);
3629 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x0007);
3632 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_PA
, 0, 3);
3633 b43_nphy_rf_ctl_override(dev
, 8, 0, 3, false);
3634 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RX2TX
);
3643 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_TRSW
, rxval
,
3645 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_TRSW
, txval
,
3650 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalcRxIqComp */
3651 static void b43_nphy_calc_rx_iq_comp(struct b43_wldev
*dev
, u8 mask
)
3657 int iq_nbits
, qq_nbits
;
3661 struct nphy_iq_est est
;
3662 struct b43_phy_n_iq_comp old
;
3663 struct b43_phy_n_iq_comp
new = { };
3669 b43_nphy_rx_iq_coeffs(dev
, false, &old
);
3670 b43_nphy_rx_iq_coeffs(dev
, true, &new);
3671 b43_nphy_rx_iq_est(dev
, &est
, 0x4000, 32, false);
3674 for (i
= 0; i
< 2; i
++) {
3675 if (i
== 0 && (mask
& 1)) {
3679 } else if (i
== 1 && (mask
& 2)) {
3692 iq_nbits
= fls(abs(iq
));
3695 arsh
= iq_nbits
- 20;
3697 a
= -((iq
<< (30 - iq_nbits
)) + (ii
>> (1 + arsh
)));
3700 a
= -((iq
<< (30 - iq_nbits
)) + (ii
<< (-1 - arsh
)));
3709 brsh
= qq_nbits
- 11;
3711 b
= (qq
<< (31 - qq_nbits
));
3714 b
= (qq
<< (31 - qq_nbits
));
3721 b
= int_sqrt(b
/ tmp
- a
* a
) - (1 << 10);
3723 if (i
== 0 && (mask
& 0x1)) {
3724 if (dev
->phy
.rev
>= 3) {
3731 } else if (i
== 1 && (mask
& 0x2)) {
3732 if (dev
->phy
.rev
>= 3) {
3745 b43_nphy_rx_iq_coeffs(dev
, true, &new);
3748 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxIqWar */
3749 static void b43_nphy_tx_iq_workaround(struct b43_wldev
*dev
)
3752 b43_ntab_read_bulk(dev
, B43_NTAB16(0xF, 0x50), 4, array
);
3754 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_NPHY_TXIQW0
, array
[0]);
3755 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_NPHY_TXIQW1
, array
[1]);
3756 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_NPHY_TXIQW2
, array
[2]);
3757 b43_shm_write16(dev
, B43_SHM_SHARED
, B43_SHM_SH_NPHY_TXIQW3
, array
[3]);
3760 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SpurWar */
3761 static void b43_nphy_spur_workaround(struct b43_wldev
*dev
)
3763 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3765 u8 channel
= dev
->phy
.channel
;
3766 int tone
[2] = { 57, 58 };
3767 u32 noise
[2] = { 0x3FF, 0x3FF };
3769 B43_WARN_ON(dev
->phy
.rev
< 3);
3771 if (nphy
->hang_avoid
)
3772 b43_nphy_stay_in_carrier_search(dev
, 1);
3774 if (nphy
->gband_spurwar_en
) {
3775 /* TODO: N PHY Adjust Analog Pfbw (7) */
3776 if (channel
== 11 && dev
->phy
.is_40mhz
)
3777 ; /* TODO: N PHY Adjust Min Noise Var(2, tone, noise)*/
3779 ; /* TODO: N PHY Adjust Min Noise Var(0, NULL, NULL)*/
3780 /* TODO: N PHY Adjust CRS Min Power (0x1E) */
3783 if (nphy
->aband_spurwar_en
) {
3784 if (channel
== 54) {
3787 } else if (channel
== 38 || channel
== 102 || channel
== 118) {
3788 if (0 /* FIXME */) {
3795 } else if (channel
== 134) {
3798 } else if (channel
== 151) {
3801 } else if (channel
== 153 || channel
== 161) {
3809 if (!tone
[0] && !noise
[0])
3810 ; /* TODO: N PHY Adjust Min Noise Var(1, tone, noise)*/
3812 ; /* TODO: N PHY Adjust Min Noise Var(0, NULL, NULL)*/
3815 if (nphy
->hang_avoid
)
3816 b43_nphy_stay_in_carrier_search(dev
, 0);
3819 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlCoefSetup */
3820 static void b43_nphy_tx_pwr_ctrl_coef_setup(struct b43_wldev
*dev
)
3822 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3825 u32 cur_real
, cur_imag
, real_part
, imag_part
;
3829 if (nphy
->hang_avoid
)
3830 b43_nphy_stay_in_carrier_search(dev
, true);
3832 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 80), 7, buffer
);
3834 for (i
= 0; i
< 2; i
++) {
3835 tmp
= ((buffer
[i
* 2] & 0x3FF) << 10) |
3836 (buffer
[i
* 2 + 1] & 0x3FF);
3837 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
,
3838 (((i
+ 26) << 10) | 320));
3839 for (j
= 0; j
< 128; j
++) {
3840 b43_phy_write(dev
, B43_NPHY_TABLE_DATAHI
,
3841 ((tmp
>> 16) & 0xFFFF));
3842 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
,
3847 for (i
= 0; i
< 2; i
++) {
3848 tmp
= buffer
[5 + i
];
3849 real_part
= (tmp
>> 8) & 0xFF;
3850 imag_part
= (tmp
& 0xFF);
3851 b43_phy_write(dev
, B43_NPHY_TABLE_ADDR
,
3852 (((i
+ 26) << 10) | 448));
3854 if (dev
->phy
.rev
>= 3) {
3855 cur_real
= real_part
;
3856 cur_imag
= imag_part
;
3857 tmp
= ((cur_real
& 0xFF) << 8) | (cur_imag
& 0xFF);
3860 for (j
= 0; j
< 128; j
++) {
3861 if (dev
->phy
.rev
< 3) {
3862 cur_real
= (real_part
* loscale
[j
] + 128) >> 8;
3863 cur_imag
= (imag_part
* loscale
[j
] + 128) >> 8;
3864 tmp
= ((cur_real
& 0xFF) << 8) |
3867 b43_phy_write(dev
, B43_NPHY_TABLE_DATAHI
,
3868 ((tmp
>> 16) & 0xFFFF));
3869 b43_phy_write(dev
, B43_NPHY_TABLE_DATALO
,
3874 if (dev
->phy
.rev
>= 3) {
3875 b43_shm_write16(dev
, B43_SHM_SHARED
,
3876 B43_SHM_SH_NPHY_TXPWR_INDX0
, 0xFFFF);
3877 b43_shm_write16(dev
, B43_SHM_SHARED
,
3878 B43_SHM_SH_NPHY_TXPWR_INDX1
, 0xFFFF);
3881 if (nphy
->hang_avoid
)
3882 b43_nphy_stay_in_carrier_search(dev
, false);
3886 * Restore RSSI Calibration
3887 * http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreRssiCal
3889 static void b43_nphy_restore_rssi_cal(struct b43_wldev
*dev
)
3891 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3893 u16
*rssical_radio_regs
= NULL
;
3894 u16
*rssical_phy_regs
= NULL
;
3896 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
3897 if (!nphy
->rssical_chanspec_2G
.center_freq
)
3899 rssical_radio_regs
= nphy
->rssical_cache
.rssical_radio_regs_2G
;
3900 rssical_phy_regs
= nphy
->rssical_cache
.rssical_phy_regs_2G
;
3902 if (!nphy
->rssical_chanspec_5G
.center_freq
)
3904 rssical_radio_regs
= nphy
->rssical_cache
.rssical_radio_regs_5G
;
3905 rssical_phy_regs
= nphy
->rssical_cache
.rssical_phy_regs_5G
;
3908 if (dev
->phy
.rev
>= 7) {
3910 b43_radio_maskset(dev
, B2056_RX0
| B2056_RX_RSSI_MISC
, 0xE3,
3911 rssical_radio_regs
[0]);
3912 b43_radio_maskset(dev
, B2056_RX1
| B2056_RX_RSSI_MISC
, 0xE3,
3913 rssical_radio_regs
[1]);
3916 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_Z
, rssical_phy_regs
[0]);
3917 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Z
, rssical_phy_regs
[1]);
3918 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_Z
, rssical_phy_regs
[2]);
3919 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Z
, rssical_phy_regs
[3]);
3921 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_X
, rssical_phy_regs
[4]);
3922 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_X
, rssical_phy_regs
[5]);
3923 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_X
, rssical_phy_regs
[6]);
3924 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_X
, rssical_phy_regs
[7]);
3926 b43_phy_write(dev
, B43_NPHY_RSSIMC_0I_RSSI_Y
, rssical_phy_regs
[8]);
3927 b43_phy_write(dev
, B43_NPHY_RSSIMC_0Q_RSSI_Y
, rssical_phy_regs
[9]);
3928 b43_phy_write(dev
, B43_NPHY_RSSIMC_1I_RSSI_Y
, rssical_phy_regs
[10]);
3929 b43_phy_write(dev
, B43_NPHY_RSSIMC_1Q_RSSI_Y
, rssical_phy_regs
[11]);
3932 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalRadioSetup */
3933 static void b43_nphy_tx_cal_radio_setup(struct b43_wldev
*dev
)
3935 struct b43_phy_n
*nphy
= dev
->phy
.n
;
3936 u16
*save
= nphy
->tx_rx_cal_radio_saveregs
;
3940 if (dev
->phy
.rev
>= 3) {
3941 for (i
= 0; i
< 2; i
++) {
3942 tmp
= (i
== 0) ? 0x2000 : 0x3000;
3945 save
[offset
+ 0] = b43_radio_read(dev
, B2055_CAL_RVARCTL
);
3946 save
[offset
+ 1] = b43_radio_read(dev
, B2055_CAL_LPOCTL
);
3947 save
[offset
+ 2] = b43_radio_read(dev
, B2055_CAL_TS
);
3948 save
[offset
+ 3] = b43_radio_read(dev
, B2055_CAL_RCCALRTS
);
3949 save
[offset
+ 4] = b43_radio_read(dev
, B2055_CAL_RCALRTS
);
3950 save
[offset
+ 5] = b43_radio_read(dev
, B2055_PADDRV
);
3951 save
[offset
+ 6] = b43_radio_read(dev
, B2055_XOCTL1
);
3952 save
[offset
+ 7] = b43_radio_read(dev
, B2055_XOCTL2
);
3953 save
[offset
+ 8] = b43_radio_read(dev
, B2055_XOREGUL
);
3954 save
[offset
+ 9] = b43_radio_read(dev
, B2055_XOMISC
);
3955 save
[offset
+ 10] = b43_radio_read(dev
, B2055_PLL_LFC1
);
3957 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
3958 b43_radio_write(dev
, tmp
| B2055_CAL_RVARCTL
, 0x0A);
3959 b43_radio_write(dev
, tmp
| B2055_CAL_LPOCTL
, 0x40);
3960 b43_radio_write(dev
, tmp
| B2055_CAL_TS
, 0x55);
3961 b43_radio_write(dev
, tmp
| B2055_CAL_RCCALRTS
, 0);
3962 b43_radio_write(dev
, tmp
| B2055_CAL_RCALRTS
, 0);
3963 if (nphy
->ipa5g_on
) {
3964 b43_radio_write(dev
, tmp
| B2055_PADDRV
, 4);
3965 b43_radio_write(dev
, tmp
| B2055_XOCTL1
, 1);
3967 b43_radio_write(dev
, tmp
| B2055_PADDRV
, 0);
3968 b43_radio_write(dev
, tmp
| B2055_XOCTL1
, 0x2F);
3970 b43_radio_write(dev
, tmp
| B2055_XOCTL2
, 0);
3972 b43_radio_write(dev
, tmp
| B2055_CAL_RVARCTL
, 0x06);
3973 b43_radio_write(dev
, tmp
| B2055_CAL_LPOCTL
, 0x40);
3974 b43_radio_write(dev
, tmp
| B2055_CAL_TS
, 0x55);
3975 b43_radio_write(dev
, tmp
| B2055_CAL_RCCALRTS
, 0);
3976 b43_radio_write(dev
, tmp
| B2055_CAL_RCALRTS
, 0);
3977 b43_radio_write(dev
, tmp
| B2055_XOCTL1
, 0);
3978 if (nphy
->ipa2g_on
) {
3979 b43_radio_write(dev
, tmp
| B2055_PADDRV
, 6);
3980 b43_radio_write(dev
, tmp
| B2055_XOCTL2
,
3981 (dev
->phy
.rev
< 5) ? 0x11 : 0x01);
3983 b43_radio_write(dev
, tmp
| B2055_PADDRV
, 0);
3984 b43_radio_write(dev
, tmp
| B2055_XOCTL2
, 0);
3987 b43_radio_write(dev
, tmp
| B2055_XOREGUL
, 0);
3988 b43_radio_write(dev
, tmp
| B2055_XOMISC
, 0);
3989 b43_radio_write(dev
, tmp
| B2055_PLL_LFC1
, 0);
3992 save
[0] = b43_radio_read(dev
, B2055_C1_TX_RF_IQCAL1
);
3993 b43_radio_write(dev
, B2055_C1_TX_RF_IQCAL1
, 0x29);
3995 save
[1] = b43_radio_read(dev
, B2055_C1_TX_RF_IQCAL2
);
3996 b43_radio_write(dev
, B2055_C1_TX_RF_IQCAL2
, 0x54);
3998 save
[2] = b43_radio_read(dev
, B2055_C2_TX_RF_IQCAL1
);
3999 b43_radio_write(dev
, B2055_C2_TX_RF_IQCAL1
, 0x29);
4001 save
[3] = b43_radio_read(dev
, B2055_C2_TX_RF_IQCAL2
);
4002 b43_radio_write(dev
, B2055_C2_TX_RF_IQCAL2
, 0x54);
4004 save
[3] = b43_radio_read(dev
, B2055_C1_PWRDET_RXTX
);
4005 save
[4] = b43_radio_read(dev
, B2055_C2_PWRDET_RXTX
);
4007 if (!(b43_phy_read(dev
, B43_NPHY_BANDCTL
) &
4008 B43_NPHY_BANDCTL_5GHZ
)) {
4009 b43_radio_write(dev
, B2055_C1_PWRDET_RXTX
, 0x04);
4010 b43_radio_write(dev
, B2055_C2_PWRDET_RXTX
, 0x04);
4012 b43_radio_write(dev
, B2055_C1_PWRDET_RXTX
, 0x20);
4013 b43_radio_write(dev
, B2055_C2_PWRDET_RXTX
, 0x20);
4016 if (dev
->phy
.rev
< 2) {
4017 b43_radio_set(dev
, B2055_C1_TX_BB_MXGM
, 0x20);
4018 b43_radio_set(dev
, B2055_C2_TX_BB_MXGM
, 0x20);
4020 b43_radio_mask(dev
, B2055_C1_TX_BB_MXGM
, ~0x20);
4021 b43_radio_mask(dev
, B2055_C2_TX_BB_MXGM
, ~0x20);
4026 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/UpdateTxCalLadder */
4027 static void b43_nphy_update_tx_cal_ladder(struct b43_wldev
*dev
, u16 core
)
4029 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4033 u16 tmp
= nphy
->txcal_bbmult
;
4038 for (i
= 0; i
< 18; i
++) {
4039 scale
= (ladder_lo
[i
].percent
* tmp
) / 100;
4040 entry
= ((scale
& 0xFF) << 8) | ladder_lo
[i
].g_env
;
4041 b43_ntab_write(dev
, B43_NTAB16(15, i
), entry
);
4043 scale
= (ladder_iq
[i
].percent
* tmp
) / 100;
4044 entry
= ((scale
& 0xFF) << 8) | ladder_iq
[i
].g_env
;
4045 b43_ntab_write(dev
, B43_NTAB16(15, i
+ 32), entry
);
4049 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ExtPaSetTxDigiFilts */
4050 static void b43_nphy_ext_pa_set_tx_dig_filters(struct b43_wldev
*dev
)
4053 for (i
= 0; i
< 15; i
++)
4054 b43_phy_write(dev
, B43_PHY_N(0x2C5 + i
),
4055 tbl_tx_filter_coef_rev4
[2][i
]);
4058 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/IpaSetTxDigiFilts */
4059 static void b43_nphy_int_pa_set_tx_dig_filters(struct b43_wldev
*dev
)
4062 /* B43_NPHY_TXF_20CO_S0A1, B43_NPHY_TXF_40CO_S0A1, unknown */
4063 static const u16 offset
[] = { 0x186, 0x195, 0x2C5 };
4065 for (i
= 0; i
< 3; i
++)
4066 for (j
= 0; j
< 15; j
++)
4067 b43_phy_write(dev
, B43_PHY_N(offset
[i
] + j
),
4068 tbl_tx_filter_coef_rev4
[i
][j
]);
4070 if (dev
->phy
.is_40mhz
) {
4071 for (j
= 0; j
< 15; j
++)
4072 b43_phy_write(dev
, B43_PHY_N(offset
[0] + j
),
4073 tbl_tx_filter_coef_rev4
[3][j
]);
4074 } else if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
) {
4075 for (j
= 0; j
< 15; j
++)
4076 b43_phy_write(dev
, B43_PHY_N(offset
[0] + j
),
4077 tbl_tx_filter_coef_rev4
[5][j
]);
4080 if (dev
->phy
.channel
== 14)
4081 for (j
= 0; j
< 15; j
++)
4082 b43_phy_write(dev
, B43_PHY_N(offset
[0] + j
),
4083 tbl_tx_filter_coef_rev4
[6][j
]);
4086 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GetTxGain */
4087 static struct nphy_txgains
b43_nphy_get_tx_gains(struct b43_wldev
*dev
)
4089 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4092 struct nphy_txgains target
;
4093 const u32
*table
= NULL
;
4095 if (!nphy
->txpwrctrl
) {
4098 if (nphy
->hang_avoid
)
4099 b43_nphy_stay_in_carrier_search(dev
, true);
4100 b43_ntab_read_bulk(dev
, B43_NTAB16(7, 0x110), 2, curr_gain
);
4101 if (nphy
->hang_avoid
)
4102 b43_nphy_stay_in_carrier_search(dev
, false);
4104 for (i
= 0; i
< 2; ++i
) {
4105 if (dev
->phy
.rev
>= 3) {
4106 target
.ipa
[i
] = curr_gain
[i
] & 0x000F;
4107 target
.pad
[i
] = (curr_gain
[i
] & 0x00F0) >> 4;
4108 target
.pga
[i
] = (curr_gain
[i
] & 0x0F00) >> 8;
4109 target
.txgm
[i
] = (curr_gain
[i
] & 0x7000) >> 12;
4111 target
.ipa
[i
] = curr_gain
[i
] & 0x0003;
4112 target
.pad
[i
] = (curr_gain
[i
] & 0x000C) >> 2;
4113 target
.pga
[i
] = (curr_gain
[i
] & 0x0070) >> 4;
4114 target
.txgm
[i
] = (curr_gain
[i
] & 0x0380) >> 7;
4120 index
[0] = (b43_phy_read(dev
, B43_NPHY_C1_TXPCTL_STAT
) &
4121 B43_NPHY_TXPCTL_STAT_BIDX
) >>
4122 B43_NPHY_TXPCTL_STAT_BIDX_SHIFT
;
4123 index
[1] = (b43_phy_read(dev
, B43_NPHY_C2_TXPCTL_STAT
) &
4124 B43_NPHY_TXPCTL_STAT_BIDX
) >>
4125 B43_NPHY_TXPCTL_STAT_BIDX_SHIFT
;
4127 for (i
= 0; i
< 2; ++i
) {
4128 table
= b43_nphy_get_tx_gain_table(dev
);
4129 if (dev
->phy
.rev
>= 3) {
4130 target
.ipa
[i
] = (table
[index
[i
]] >> 16) & 0xF;
4131 target
.pad
[i
] = (table
[index
[i
]] >> 20) & 0xF;
4132 target
.pga
[i
] = (table
[index
[i
]] >> 24) & 0xF;
4133 target
.txgm
[i
] = (table
[index
[i
]] >> 28) & 0xF;
4135 target
.ipa
[i
] = (table
[index
[i
]] >> 16) & 0x3;
4136 target
.pad
[i
] = (table
[index
[i
]] >> 18) & 0x3;
4137 target
.pga
[i
] = (table
[index
[i
]] >> 20) & 0x7;
4138 target
.txgm
[i
] = (table
[index
[i
]] >> 23) & 0x7;
4146 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalPhyCleanup */
4147 static void b43_nphy_tx_cal_phy_cleanup(struct b43_wldev
*dev
)
4149 u16
*regs
= dev
->phy
.n
->tx_rx_cal_phy_saveregs
;
4151 if (dev
->phy
.rev
>= 3) {
4152 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, regs
[0]);
4153 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, regs
[1]);
4154 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, regs
[2]);
4155 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, regs
[3]);
4156 b43_phy_write(dev
, B43_NPHY_BBCFG
, regs
[4]);
4157 b43_ntab_write(dev
, B43_NTAB16(8, 3), regs
[5]);
4158 b43_ntab_write(dev
, B43_NTAB16(8, 19), regs
[6]);
4159 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, regs
[7]);
4160 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, regs
[8]);
4161 b43_phy_write(dev
, B43_NPHY_PAPD_EN0
, regs
[9]);
4162 b43_phy_write(dev
, B43_NPHY_PAPD_EN1
, regs
[10]);
4163 b43_nphy_reset_cca(dev
);
4165 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C1
, 0x0FFF, regs
[0]);
4166 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C2
, 0x0FFF, regs
[1]);
4167 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, regs
[2]);
4168 b43_ntab_write(dev
, B43_NTAB16(8, 2), regs
[3]);
4169 b43_ntab_write(dev
, B43_NTAB16(8, 18), regs
[4]);
4170 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, regs
[5]);
4171 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, regs
[6]);
4175 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalPhySetup */
4176 static void b43_nphy_tx_cal_phy_setup(struct b43_wldev
*dev
)
4178 u16
*regs
= dev
->phy
.n
->tx_rx_cal_phy_saveregs
;
4181 regs
[0] = b43_phy_read(dev
, B43_NPHY_AFECTL_C1
);
4182 regs
[1] = b43_phy_read(dev
, B43_NPHY_AFECTL_C2
);
4183 if (dev
->phy
.rev
>= 3) {
4184 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C1
, 0xF0FF, 0x0A00);
4185 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C2
, 0xF0FF, 0x0A00);
4187 tmp
= b43_phy_read(dev
, B43_NPHY_AFECTL_OVER1
);
4189 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, tmp
| 0x0600);
4191 tmp
= b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
4193 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, tmp
| 0x0600);
4195 regs
[4] = b43_phy_read(dev
, B43_NPHY_BBCFG
);
4196 b43_phy_mask(dev
, B43_NPHY_BBCFG
,
4197 ~B43_NPHY_BBCFG_RSTRX
& 0xFFFF);
4199 tmp
= b43_ntab_read(dev
, B43_NTAB16(8, 3));
4201 b43_ntab_write(dev
, B43_NTAB16(8, 3), 0);
4203 tmp
= b43_ntab_read(dev
, B43_NTAB16(8, 19));
4205 b43_ntab_write(dev
, B43_NTAB16(8, 19), 0);
4206 regs
[7] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC1
);
4207 regs
[8] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC2
);
4209 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_PA
, 1, 3);
4210 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_TRSW
, 2, 1);
4211 b43_nphy_rf_ctl_intc_override(dev
, N_INTC_OVERRIDE_TRSW
, 8, 2);
4213 regs
[9] = b43_phy_read(dev
, B43_NPHY_PAPD_EN0
);
4214 regs
[10] = b43_phy_read(dev
, B43_NPHY_PAPD_EN1
);
4215 b43_phy_mask(dev
, B43_NPHY_PAPD_EN0
, ~0x0001);
4216 b43_phy_mask(dev
, B43_NPHY_PAPD_EN1
, ~0x0001);
4218 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C1
, 0x0FFF, 0xA000);
4219 b43_phy_maskset(dev
, B43_NPHY_AFECTL_C2
, 0x0FFF, 0xA000);
4220 tmp
= b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
4222 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, tmp
| 0x3000);
4223 tmp
= b43_ntab_read(dev
, B43_NTAB16(8, 2));
4226 b43_ntab_write(dev
, B43_NTAB16(8, 2), tmp
);
4227 tmp
= b43_ntab_read(dev
, B43_NTAB16(8, 18));
4230 b43_ntab_write(dev
, B43_NTAB16(8, 18), tmp
);
4231 regs
[5] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC1
);
4232 regs
[6] = b43_phy_read(dev
, B43_NPHY_RFCTL_INTC2
);
4233 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_5GHZ
)
4237 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, tmp
);
4238 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, tmp
);
4242 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SaveCal */
4243 static void b43_nphy_save_cal(struct b43_wldev
*dev
)
4245 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4247 struct b43_phy_n_iq_comp
*rxcal_coeffs
= NULL
;
4248 u16
*txcal_radio_regs
= NULL
;
4249 struct b43_chanspec
*iqcal_chanspec
;
4252 if (nphy
->hang_avoid
)
4253 b43_nphy_stay_in_carrier_search(dev
, 1);
4255 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
4256 rxcal_coeffs
= &nphy
->cal_cache
.rxcal_coeffs_2G
;
4257 txcal_radio_regs
= nphy
->cal_cache
.txcal_radio_regs_2G
;
4258 iqcal_chanspec
= &nphy
->iqcal_chanspec_2G
;
4259 table
= nphy
->cal_cache
.txcal_coeffs_2G
;
4261 rxcal_coeffs
= &nphy
->cal_cache
.rxcal_coeffs_5G
;
4262 txcal_radio_regs
= nphy
->cal_cache
.txcal_radio_regs_5G
;
4263 iqcal_chanspec
= &nphy
->iqcal_chanspec_5G
;
4264 table
= nphy
->cal_cache
.txcal_coeffs_5G
;
4267 b43_nphy_rx_iq_coeffs(dev
, false, rxcal_coeffs
);
4268 /* TODO use some definitions */
4269 if (dev
->phy
.rev
>= 3) {
4270 txcal_radio_regs
[0] = b43_radio_read(dev
, 0x2021);
4271 txcal_radio_regs
[1] = b43_radio_read(dev
, 0x2022);
4272 txcal_radio_regs
[2] = b43_radio_read(dev
, 0x3021);
4273 txcal_radio_regs
[3] = b43_radio_read(dev
, 0x3022);
4274 txcal_radio_regs
[4] = b43_radio_read(dev
, 0x2023);
4275 txcal_radio_regs
[5] = b43_radio_read(dev
, 0x2024);
4276 txcal_radio_regs
[6] = b43_radio_read(dev
, 0x3023);
4277 txcal_radio_regs
[7] = b43_radio_read(dev
, 0x3024);
4279 txcal_radio_regs
[0] = b43_radio_read(dev
, 0x8B);
4280 txcal_radio_regs
[1] = b43_radio_read(dev
, 0xBA);
4281 txcal_radio_regs
[2] = b43_radio_read(dev
, 0x8D);
4282 txcal_radio_regs
[3] = b43_radio_read(dev
, 0xBC);
4284 iqcal_chanspec
->center_freq
= dev
->phy
.channel_freq
;
4285 iqcal_chanspec
->channel_type
= dev
->phy
.channel_type
;
4286 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 80), 8, table
);
4288 if (nphy
->hang_avoid
)
4289 b43_nphy_stay_in_carrier_search(dev
, 0);
4292 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreCal */
4293 static void b43_nphy_restore_cal(struct b43_wldev
*dev
)
4295 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4302 u16
*txcal_radio_regs
= NULL
;
4303 struct b43_phy_n_iq_comp
*rxcal_coeffs
= NULL
;
4305 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
4306 if (!nphy
->iqcal_chanspec_2G
.center_freq
)
4308 table
= nphy
->cal_cache
.txcal_coeffs_2G
;
4309 loft
= &nphy
->cal_cache
.txcal_coeffs_2G
[5];
4311 if (!nphy
->iqcal_chanspec_5G
.center_freq
)
4313 table
= nphy
->cal_cache
.txcal_coeffs_5G
;
4314 loft
= &nphy
->cal_cache
.txcal_coeffs_5G
[5];
4317 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 80), 4, table
);
4319 for (i
= 0; i
< 4; i
++) {
4320 if (dev
->phy
.rev
>= 3)
4326 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 88), 4, coef
);
4327 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 85), 2, loft
);
4328 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 93), 2, loft
);
4330 if (dev
->phy
.rev
< 2)
4331 b43_nphy_tx_iq_workaround(dev
);
4333 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
4334 txcal_radio_regs
= nphy
->cal_cache
.txcal_radio_regs_2G
;
4335 rxcal_coeffs
= &nphy
->cal_cache
.rxcal_coeffs_2G
;
4337 txcal_radio_regs
= nphy
->cal_cache
.txcal_radio_regs_5G
;
4338 rxcal_coeffs
= &nphy
->cal_cache
.rxcal_coeffs_5G
;
4341 /* TODO use some definitions */
4342 if (dev
->phy
.rev
>= 3) {
4343 b43_radio_write(dev
, 0x2021, txcal_radio_regs
[0]);
4344 b43_radio_write(dev
, 0x2022, txcal_radio_regs
[1]);
4345 b43_radio_write(dev
, 0x3021, txcal_radio_regs
[2]);
4346 b43_radio_write(dev
, 0x3022, txcal_radio_regs
[3]);
4347 b43_radio_write(dev
, 0x2023, txcal_radio_regs
[4]);
4348 b43_radio_write(dev
, 0x2024, txcal_radio_regs
[5]);
4349 b43_radio_write(dev
, 0x3023, txcal_radio_regs
[6]);
4350 b43_radio_write(dev
, 0x3024, txcal_radio_regs
[7]);
4352 b43_radio_write(dev
, 0x8B, txcal_radio_regs
[0]);
4353 b43_radio_write(dev
, 0xBA, txcal_radio_regs
[1]);
4354 b43_radio_write(dev
, 0x8D, txcal_radio_regs
[2]);
4355 b43_radio_write(dev
, 0xBC, txcal_radio_regs
[3]);
4357 b43_nphy_rx_iq_coeffs(dev
, true, rxcal_coeffs
);
4360 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalTxIqlo */
4361 static int b43_nphy_cal_tx_iq_lo(struct b43_wldev
*dev
,
4362 struct nphy_txgains target
,
4363 bool full
, bool mphase
)
4365 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4371 u16 tmp
, core
, type
, count
, max
, numb
, last
= 0, cmd
;
4379 struct nphy_iqcal_params params
[2];
4380 bool updated
[2] = { };
4382 b43_nphy_stay_in_carrier_search(dev
, true);
4384 if (dev
->phy
.rev
>= 4) {
4385 avoid
= nphy
->hang_avoid
;
4386 nphy
->hang_avoid
= false;
4389 b43_ntab_read_bulk(dev
, B43_NTAB16(7, 0x110), 2, save
);
4391 for (i
= 0; i
< 2; i
++) {
4392 b43_nphy_iq_cal_gain_params(dev
, i
, target
, ¶ms
[i
]);
4393 gain
[i
] = params
[i
].cal_gain
;
4396 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x110), 2, gain
);
4398 b43_nphy_tx_cal_radio_setup(dev
);
4399 b43_nphy_tx_cal_phy_setup(dev
);
4401 phy6or5x
= dev
->phy
.rev
>= 6 ||
4402 (dev
->phy
.rev
== 5 && nphy
->ipa2g_on
&&
4403 b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
);
4405 if (dev
->phy
.is_40mhz
) {
4406 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 0), 18,
4407 tbl_tx_iqlo_cal_loft_ladder_40
);
4408 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 32), 18,
4409 tbl_tx_iqlo_cal_iqimb_ladder_40
);
4411 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 0), 18,
4412 tbl_tx_iqlo_cal_loft_ladder_20
);
4413 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 32), 18,
4414 tbl_tx_iqlo_cal_iqimb_ladder_20
);
4418 b43_phy_write(dev
, B43_NPHY_IQLOCAL_CMDGCTL
, 0x8AA9);
4420 if (!dev
->phy
.is_40mhz
)
4425 if (nphy
->mphase_cal_phase_id
> 2)
4426 b43_nphy_run_samples(dev
, (dev
->phy
.is_40mhz
? 40 : 20) * 8,
4427 0xFFFF, 0, true, false);
4429 error
= b43_nphy_tx_tone(dev
, freq
, 250, true, false);
4432 if (nphy
->mphase_cal_phase_id
> 2) {
4433 table
= nphy
->mphase_txcal_bestcoeffs
;
4435 if (dev
->phy
.rev
< 3)
4438 if (!full
&& nphy
->txiqlocal_coeffsvalid
) {
4439 table
= nphy
->txiqlocal_bestc
;
4441 if (dev
->phy
.rev
< 3)
4445 if (dev
->phy
.rev
>= 3) {
4446 table
= tbl_tx_iqlo_cal_startcoefs_nphyrev3
;
4447 length
= B43_NTAB_TX_IQLO_CAL_STARTCOEFS_REV3
;
4449 table
= tbl_tx_iqlo_cal_startcoefs
;
4450 length
= B43_NTAB_TX_IQLO_CAL_STARTCOEFS
;
4455 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 64), length
, table
);
4458 if (dev
->phy
.rev
>= 3)
4459 max
= B43_NTAB_TX_IQLO_CAL_CMDS_FULLCAL_REV3
;
4461 max
= B43_NTAB_TX_IQLO_CAL_CMDS_FULLCAL
;
4463 if (dev
->phy
.rev
>= 3)
4464 max
= B43_NTAB_TX_IQLO_CAL_CMDS_RECAL_REV3
;
4466 max
= B43_NTAB_TX_IQLO_CAL_CMDS_RECAL
;
4470 count
= nphy
->mphase_txcal_cmdidx
;
4472 (u16
)(count
+ nphy
->mphase_txcal_numcmds
));
4478 for (; count
< numb
; count
++) {
4480 if (dev
->phy
.rev
>= 3)
4481 cmd
= tbl_tx_iqlo_cal_cmds_fullcal_nphyrev3
[count
];
4483 cmd
= tbl_tx_iqlo_cal_cmds_fullcal
[count
];
4485 if (dev
->phy
.rev
>= 3)
4486 cmd
= tbl_tx_iqlo_cal_cmds_recal_nphyrev3
[count
];
4488 cmd
= tbl_tx_iqlo_cal_cmds_recal
[count
];
4491 core
= (cmd
& 0x3000) >> 12;
4492 type
= (cmd
& 0x0F00) >> 8;
4494 if (phy6or5x
&& updated
[core
] == 0) {
4495 b43_nphy_update_tx_cal_ladder(dev
, core
);
4496 updated
[core
] = true;
4499 tmp
= (params
[core
].ncorr
[type
] << 8) | 0x66;
4500 b43_phy_write(dev
, B43_NPHY_IQLOCAL_CMDNNUM
, tmp
);
4502 if (type
== 1 || type
== 3 || type
== 4) {
4503 buffer
[0] = b43_ntab_read(dev
,
4504 B43_NTAB16(15, 69 + core
));
4505 diq_start
= buffer
[0];
4507 b43_ntab_write(dev
, B43_NTAB16(15, 69 + core
),
4511 b43_phy_write(dev
, B43_NPHY_IQLOCAL_CMD
, cmd
);
4512 for (i
= 0; i
< 2000; i
++) {
4513 tmp
= b43_phy_read(dev
, B43_NPHY_IQLOCAL_CMD
);
4519 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 96), length
,
4521 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 64), length
,
4524 if (type
== 1 || type
== 3 || type
== 4)
4525 buffer
[0] = diq_start
;
4529 nphy
->mphase_txcal_cmdidx
= (numb
>= max
) ? 0 : numb
;
4531 last
= (dev
->phy
.rev
< 3) ? 6 : 7;
4533 if (!mphase
|| nphy
->mphase_cal_phase_id
== last
) {
4534 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 96), 4, buffer
);
4535 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 80), 4, buffer
);
4536 if (dev
->phy
.rev
< 3) {
4542 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 88), 4,
4544 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 101), 2,
4546 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 85), 2,
4548 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 93), 2,
4551 if (dev
->phy
.rev
< 3)
4553 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 96), length
,
4554 nphy
->txiqlocal_bestc
);
4555 nphy
->txiqlocal_coeffsvalid
= true;
4556 nphy
->txiqlocal_chanspec
.center_freq
=
4557 dev
->phy
.channel_freq
;
4558 nphy
->txiqlocal_chanspec
.channel_type
=
4559 dev
->phy
.channel_type
;
4562 if (dev
->phy
.rev
< 3)
4564 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 96), length
,
4565 nphy
->mphase_txcal_bestcoeffs
);
4568 b43_nphy_stop_playback(dev
);
4569 b43_phy_write(dev
, B43_NPHY_IQLOCAL_CMDGCTL
, 0);
4572 b43_nphy_tx_cal_phy_cleanup(dev
);
4573 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x110), 2, save
);
4575 if (dev
->phy
.rev
< 2 && (!mphase
|| nphy
->mphase_cal_phase_id
== last
))
4576 b43_nphy_tx_iq_workaround(dev
);
4578 if (dev
->phy
.rev
>= 4)
4579 nphy
->hang_avoid
= avoid
;
4581 b43_nphy_stay_in_carrier_search(dev
, false);
4586 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ReapplyTxCalCoeffs */
4587 static void b43_nphy_reapply_tx_cal_coeffs(struct b43_wldev
*dev
)
4589 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4594 if (!nphy
->txiqlocal_coeffsvalid
||
4595 nphy
->txiqlocal_chanspec
.center_freq
!= dev
->phy
.channel_freq
||
4596 nphy
->txiqlocal_chanspec
.channel_type
!= dev
->phy
.channel_type
)
4599 b43_ntab_read_bulk(dev
, B43_NTAB16(15, 80), 7, buffer
);
4600 for (i
= 0; i
< 4; i
++) {
4601 if (buffer
[i
] != nphy
->txiqlocal_bestc
[i
]) {
4608 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 80), 4,
4609 nphy
->txiqlocal_bestc
);
4610 for (i
= 0; i
< 4; i
++)
4612 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 88), 4,
4614 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 85), 2,
4615 &nphy
->txiqlocal_bestc
[5]);
4616 b43_ntab_write_bulk(dev
, B43_NTAB16(15, 93), 2,
4617 &nphy
->txiqlocal_bestc
[5]);
4621 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalRxIqRev2 */
4622 static int b43_nphy_rev2_cal_rx_iq(struct b43_wldev
*dev
,
4623 struct nphy_txgains target
, u8 type
, bool debug
)
4625 struct b43_phy_n
*nphy
= dev
->phy
.n
;
4630 u16
uninitialized_var(cur_hpf1
), uninitialized_var(cur_hpf2
), cur_lna
;
4632 enum ieee80211_band band
;
4636 u16 lna
[3] = { 3, 3, 1 };
4637 u16 hpf1
[3] = { 7, 2, 0 };
4638 u16 hpf2
[3] = { 2, 0, 0 };
4642 struct nphy_iqcal_params cal_params
[2];
4643 struct nphy_iq_est est
;
4645 bool playtone
= true;
4648 b43_nphy_stay_in_carrier_search(dev
, 1);
4650 if (dev
->phy
.rev
< 2)
4651 b43_nphy_reapply_tx_cal_coeffs(dev
);
4652 b43_ntab_read_bulk(dev
, B43_NTAB16(7, 0x110), 2, gain_save
);
4653 for (i
= 0; i
< 2; i
++) {
4654 b43_nphy_iq_cal_gain_params(dev
, i
, target
, &cal_params
[i
]);
4655 cal_gain
[i
] = cal_params
[i
].cal_gain
;
4657 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x110), 2, cal_gain
);
4659 for (i
= 0; i
< 2; i
++) {
4661 rfctl
[0] = B43_NPHY_RFCTL_INTC1
;
4662 rfctl
[1] = B43_NPHY_RFCTL_INTC2
;
4663 afectl_core
= B43_NPHY_AFECTL_C1
;
4665 rfctl
[0] = B43_NPHY_RFCTL_INTC2
;
4666 rfctl
[1] = B43_NPHY_RFCTL_INTC1
;
4667 afectl_core
= B43_NPHY_AFECTL_C2
;
4670 tmp
[1] = b43_phy_read(dev
, B43_NPHY_RFSEQCA
);
4671 tmp
[2] = b43_phy_read(dev
, afectl_core
);
4672 tmp
[3] = b43_phy_read(dev
, B43_NPHY_AFECTL_OVER
);
4673 tmp
[4] = b43_phy_read(dev
, rfctl
[0]);
4674 tmp
[5] = b43_phy_read(dev
, rfctl
[1]);
4676 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
,
4677 ~B43_NPHY_RFSEQCA_RXDIS
& 0xFFFF,
4678 ((1 - i
) << B43_NPHY_RFSEQCA_RXDIS_SHIFT
));
4679 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
, ~B43_NPHY_RFSEQCA_TXEN
,
4681 b43_phy_set(dev
, afectl_core
, 0x0006);
4682 b43_phy_set(dev
, B43_NPHY_AFECTL_OVER
, 0x0006);
4684 band
= b43_current_band(dev
->wl
);
4686 if (nphy
->rxcalparams
& 0xFF000000) {
4687 if (band
== IEEE80211_BAND_5GHZ
)
4688 b43_phy_write(dev
, rfctl
[0], 0x140);
4690 b43_phy_write(dev
, rfctl
[0], 0x110);
4692 if (band
== IEEE80211_BAND_5GHZ
)
4693 b43_phy_write(dev
, rfctl
[0], 0x180);
4695 b43_phy_write(dev
, rfctl
[0], 0x120);
4698 if (band
== IEEE80211_BAND_5GHZ
)
4699 b43_phy_write(dev
, rfctl
[1], 0x148);
4701 b43_phy_write(dev
, rfctl
[1], 0x114);
4703 if (nphy
->rxcalparams
& 0x10000) {
4704 b43_radio_maskset(dev
, B2055_C1_GENSPARE2
, 0xFC,
4706 b43_radio_maskset(dev
, B2055_C2_GENSPARE2
, 0xFC,
4710 for (j
= 0; j
< 4; j
++) {
4716 if (power
[1] > 10000) {
4721 if (power
[0] > 10000) {
4731 cur_lna
= lna
[index
];
4732 cur_hpf1
= hpf1
[index
];
4733 cur_hpf2
= hpf2
[index
];
4734 cur_hpf
+= desired
- hweight32(power
[index
]);
4735 cur_hpf
= clamp_val(cur_hpf
, 0, 10);
4742 tmp
[0] = ((cur_hpf2
<< 8) | (cur_hpf1
<< 4) |
4744 b43_nphy_rf_ctl_override(dev
, 0x400, tmp
[0], 3,
4746 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
4747 b43_nphy_stop_playback(dev
);
4750 ret
= b43_nphy_tx_tone(dev
, 4000,
4751 (nphy
->rxcalparams
& 0xFFFF),
4755 b43_nphy_run_samples(dev
, 160, 0xFFFF, 0,
4761 b43_nphy_rx_iq_est(dev
, &est
, 1024, 32,
4770 power
[i
] = ((real
+ imag
) / 1024) + 1;
4772 b43_nphy_calc_rx_iq_comp(dev
, 1 << i
);
4774 b43_nphy_stop_playback(dev
);
4781 b43_radio_mask(dev
, B2055_C1_GENSPARE2
, 0xFC);
4782 b43_radio_mask(dev
, B2055_C2_GENSPARE2
, 0xFC);
4783 b43_phy_write(dev
, rfctl
[1], tmp
[5]);
4784 b43_phy_write(dev
, rfctl
[0], tmp
[4]);
4785 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, tmp
[3]);
4786 b43_phy_write(dev
, afectl_core
, tmp
[2]);
4787 b43_phy_write(dev
, B43_NPHY_RFSEQCA
, tmp
[1]);
4793 b43_nphy_rf_ctl_override(dev
, 0x400, 0, 3, true);
4794 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
4795 b43_ntab_write_bulk(dev
, B43_NTAB16(7, 0x110), 2, gain_save
);
4797 b43_nphy_stay_in_carrier_search(dev
, 0);
4802 static int b43_nphy_rev3_cal_rx_iq(struct b43_wldev
*dev
,
4803 struct nphy_txgains target
, u8 type
, bool debug
)
4808 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalRxIq */
4809 static int b43_nphy_cal_rx_iq(struct b43_wldev
*dev
,
4810 struct nphy_txgains target
, u8 type
, bool debug
)
4812 if (dev
->phy
.rev
>= 3)
4813 return b43_nphy_rev3_cal_rx_iq(dev
, target
, type
, debug
);
4815 return b43_nphy_rev2_cal_rx_iq(dev
, target
, type
, debug
);
4818 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCoreSetState */
4819 static void b43_nphy_set_rx_core_state(struct b43_wldev
*dev
, u8 mask
)
4821 struct b43_phy
*phy
= &dev
->phy
;
4822 struct b43_phy_n
*nphy
= phy
->n
;
4823 /* u16 buf[16]; it's rev3+ */
4825 nphy
->phyrxchain
= mask
;
4827 if (0 /* FIXME clk */)
4830 b43_mac_suspend(dev
);
4832 if (nphy
->hang_avoid
)
4833 b43_nphy_stay_in_carrier_search(dev
, true);
4835 b43_phy_maskset(dev
, B43_NPHY_RFSEQCA
, ~B43_NPHY_RFSEQCA_RXEN
,
4836 (mask
& 0x3) << B43_NPHY_RFSEQCA_RXEN_SHIFT
);
4838 if ((mask
& 0x3) != 0x3) {
4839 b43_phy_write(dev
, B43_NPHY_HPANT_SWTHRES
, 1);
4840 if (dev
->phy
.rev
>= 3) {
4844 b43_phy_write(dev
, B43_NPHY_HPANT_SWTHRES
, 0x1E);
4845 if (dev
->phy
.rev
>= 3) {
4850 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
4852 if (nphy
->hang_avoid
)
4853 b43_nphy_stay_in_carrier_search(dev
, false);
4855 b43_mac_enable(dev
);
4858 /**************************************************
4860 **************************************************/
4862 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/MIMOConfig */
4863 static void b43_nphy_update_mimo_config(struct b43_wldev
*dev
, s32 preamble
)
4865 u16 mimocfg
= b43_phy_read(dev
, B43_NPHY_MIMOCFG
);
4867 mimocfg
|= B43_NPHY_MIMOCFG_AUTO
;
4869 mimocfg
|= B43_NPHY_MIMOCFG_GFMIX
;
4871 mimocfg
&= ~B43_NPHY_MIMOCFG_GFMIX
;
4873 b43_phy_write(dev
, B43_NPHY_MIMOCFG
, mimocfg
);
4876 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BPHYInit */
4877 static void b43_nphy_bphy_init(struct b43_wldev
*dev
)
4883 for (i
= 0; i
< 16; i
++) {
4884 b43_phy_write(dev
, B43_PHY_N_BMODE(0x88 + i
), val
);
4888 for (i
= 0; i
< 16; i
++) {
4889 b43_phy_write(dev
, B43_PHY_N_BMODE(0x98 + i
), val
);
4892 b43_phy_write(dev
, B43_PHY_N_BMODE(0x38), 0x668);
4895 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SuperSwitchInit */
4896 static void b43_nphy_superswitch_init(struct b43_wldev
*dev
, bool init
)
4898 if (dev
->phy
.rev
>= 3) {
4901 if (0 /* FIXME */) {
4902 b43_ntab_write(dev
, B43_NTAB16(9, 2), 0x211);
4903 b43_ntab_write(dev
, B43_NTAB16(9, 3), 0x222);
4904 b43_ntab_write(dev
, B43_NTAB16(9, 8), 0x144);
4905 b43_ntab_write(dev
, B43_NTAB16(9, 12), 0x188);
4908 b43_phy_write(dev
, B43_NPHY_GPIO_LOOEN
, 0);
4909 b43_phy_write(dev
, B43_NPHY_GPIO_HIOEN
, 0);
4911 switch (dev
->dev
->bus_type
) {
4912 #ifdef CONFIG_B43_BCMA
4914 bcma_chipco_gpio_control(&dev
->dev
->bdev
->bus
->drv_cc
,
4918 #ifdef CONFIG_B43_SSB
4920 ssb_chipco_gpio_control(&dev
->dev
->sdev
->bus
->chipco
,
4926 b43_maskset32(dev
, B43_MMIO_MACCTL
, ~B43_MACCTL_GPOUTSMSK
, 0);
4927 b43_maskset16(dev
, B43_MMIO_GPIO_MASK
, ~0, 0xFC00);
4928 b43_maskset16(dev
, B43_MMIO_GPIO_CONTROL
, (~0xFC00 & 0xFFFF),
4932 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_LO1
, 0x2D8);
4933 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP1
, 0x301);
4934 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_LO2
, 0x2D8);
4935 b43_phy_write(dev
, B43_NPHY_RFCTL_LUT_TRSW_UP2
, 0x301);
4940 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Init/N */
4941 static int b43_phy_initn(struct b43_wldev
*dev
)
4943 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
4944 struct b43_phy
*phy
= &dev
->phy
;
4945 struct b43_phy_n
*nphy
= phy
->n
;
4947 struct nphy_txgains target
;
4949 enum ieee80211_band tmp2
;
4953 bool do_cal
= false;
4955 if ((dev
->phy
.rev
>= 3) &&
4956 (sprom
->boardflags_lo
& B43_BFL_EXTLNA
) &&
4957 (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)) {
4958 switch (dev
->dev
->bus_type
) {
4959 #ifdef CONFIG_B43_BCMA
4961 bcma_cc_set32(&dev
->dev
->bdev
->bus
->drv_cc
,
4962 BCMA_CC_CHIPCTL
, 0x40);
4965 #ifdef CONFIG_B43_SSB
4967 chipco_set32(&dev
->dev
->sdev
->bus
->chipco
,
4968 SSB_CHIPCO_CHIPCTL
, 0x40);
4973 nphy
->deaf_count
= 0;
4974 b43_nphy_tables_init(dev
);
4975 nphy
->crsminpwr_adjusted
= false;
4976 nphy
->noisevars_adjusted
= false;
4978 /* Clear all overrides */
4979 if (dev
->phy
.rev
>= 3) {
4980 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B1S1
, 0);
4981 b43_phy_write(dev
, B43_NPHY_RFCTL_OVER
, 0);
4982 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B1S0
, 0);
4983 b43_phy_write(dev
, B43_NPHY_TXF_40CO_B32S1
, 0);
4985 b43_phy_write(dev
, B43_NPHY_RFCTL_OVER
, 0);
4987 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC1
, 0);
4988 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC2
, 0);
4989 if (dev
->phy
.rev
< 6) {
4990 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC3
, 0);
4991 b43_phy_write(dev
, B43_NPHY_RFCTL_INTC4
, 0);
4993 b43_phy_mask(dev
, B43_NPHY_RFSEQMODE
,
4994 ~(B43_NPHY_RFSEQMODE_CAOVER
|
4995 B43_NPHY_RFSEQMODE_TROVER
));
4996 if (dev
->phy
.rev
>= 3)
4997 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, 0);
4998 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, 0);
5000 if (dev
->phy
.rev
<= 2) {
5001 tmp
= (dev
->phy
.rev
== 2) ? 0x3B : 0x40;
5002 b43_phy_maskset(dev
, B43_NPHY_BPHY_CTL3
,
5003 ~B43_NPHY_BPHY_CTL3_SCALE
,
5004 tmp
<< B43_NPHY_BPHY_CTL3_SCALE_SHIFT
);
5006 b43_phy_write(dev
, B43_NPHY_AFESEQ_TX2RX_PUD_20M
, 0x20);
5007 b43_phy_write(dev
, B43_NPHY_AFESEQ_TX2RX_PUD_40M
, 0x20);
5009 if (sprom
->boardflags2_lo
& B43_BFL2_SKWRKFEM_BRD
||
5010 (dev
->dev
->board_vendor
== PCI_VENDOR_ID_APPLE
&&
5011 dev
->dev
->board_type
== BCMA_BOARD_TYPE_BCM943224M93
))
5012 b43_phy_write(dev
, B43_NPHY_TXREALFD
, 0xA0);
5014 b43_phy_write(dev
, B43_NPHY_TXREALFD
, 0xB8);
5015 b43_phy_write(dev
, B43_NPHY_MIMO_CRSTXEXT
, 0xC8);
5016 b43_phy_write(dev
, B43_NPHY_PLOAD_CSENSE_EXTLEN
, 0x50);
5017 b43_phy_write(dev
, B43_NPHY_TXRIFS_FRDEL
, 0x30);
5019 b43_nphy_update_mimo_config(dev
, nphy
->preamble_override
);
5020 b43_nphy_update_txrx_chain(dev
);
5023 b43_phy_write(dev
, B43_NPHY_DUP40_GFBL
, 0xAA8);
5024 b43_phy_write(dev
, B43_NPHY_DUP40_BL
, 0x9A4);
5027 tmp2
= b43_current_band(dev
->wl
);
5028 if (b43_nphy_ipa(dev
)) {
5029 b43_phy_set(dev
, B43_NPHY_PAPD_EN0
, 0x1);
5030 b43_phy_maskset(dev
, B43_NPHY_EPS_TABLE_ADJ0
, 0x007F,
5031 nphy
->papd_epsilon_offset
[0] << 7);
5032 b43_phy_set(dev
, B43_NPHY_PAPD_EN1
, 0x1);
5033 b43_phy_maskset(dev
, B43_NPHY_EPS_TABLE_ADJ1
, 0x007F,
5034 nphy
->papd_epsilon_offset
[1] << 7);
5035 b43_nphy_int_pa_set_tx_dig_filters(dev
);
5036 } else if (phy
->rev
>= 5) {
5037 b43_nphy_ext_pa_set_tx_dig_filters(dev
);
5040 b43_nphy_workarounds(dev
);
5042 /* Reset CCA, in init code it differs a little from standard way */
5043 b43_phy_force_clock(dev
, 1);
5044 tmp
= b43_phy_read(dev
, B43_NPHY_BBCFG
);
5045 b43_phy_write(dev
, B43_NPHY_BBCFG
, tmp
| B43_NPHY_BBCFG_RSTCCA
);
5046 b43_phy_write(dev
, B43_NPHY_BBCFG
, tmp
& ~B43_NPHY_BBCFG_RSTCCA
);
5047 b43_phy_force_clock(dev
, 0);
5049 b43_mac_phy_clock_set(dev
, true);
5051 b43_nphy_pa_override(dev
, false);
5052 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RX2TX
);
5053 b43_nphy_force_rf_sequence(dev
, B43_RFSEQ_RESET2RX
);
5054 b43_nphy_pa_override(dev
, true);
5056 b43_nphy_classifier(dev
, 0, 0);
5057 b43_nphy_read_clip_detection(dev
, clip
);
5058 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
5059 b43_nphy_bphy_init(dev
);
5061 tx_pwr_state
= nphy
->txpwrctrl
;
5062 b43_nphy_tx_power_ctrl(dev
, false);
5063 b43_nphy_tx_power_fix(dev
);
5064 b43_nphy_tx_power_ctl_idle_tssi(dev
);
5065 b43_nphy_tx_power_ctl_setup(dev
);
5066 b43_nphy_tx_gain_table_upload(dev
);
5068 if (nphy
->phyrxchain
!= 3)
5069 b43_nphy_set_rx_core_state(dev
, nphy
->phyrxchain
);
5070 if (nphy
->mphase_cal_phase_id
> 0)
5071 ;/* TODO PHY Periodic Calibration Multi-Phase Restart */
5073 do_rssi_cal
= false;
5074 if (phy
->rev
>= 3) {
5075 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
5076 do_rssi_cal
= !nphy
->rssical_chanspec_2G
.center_freq
;
5078 do_rssi_cal
= !nphy
->rssical_chanspec_5G
.center_freq
;
5081 b43_nphy_rssi_cal(dev
);
5083 b43_nphy_restore_rssi_cal(dev
);
5085 b43_nphy_rssi_cal(dev
);
5088 if (!((nphy
->measure_hold
& 0x6) != 0)) {
5089 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
5090 do_cal
= !nphy
->iqcal_chanspec_2G
.center_freq
;
5092 do_cal
= !nphy
->iqcal_chanspec_5G
.center_freq
;
5098 target
= b43_nphy_get_tx_gains(dev
);
5100 if (nphy
->antsel_type
== 2)
5101 b43_nphy_superswitch_init(dev
, true);
5102 if (nphy
->perical
!= 2) {
5103 b43_nphy_rssi_cal(dev
);
5104 if (phy
->rev
>= 3) {
5105 nphy
->cal_orig_pwr_idx
[0] =
5106 nphy
->txpwrindex
[0].index_internal
;
5107 nphy
->cal_orig_pwr_idx
[1] =
5108 nphy
->txpwrindex
[1].index_internal
;
5109 /* TODO N PHY Pre Calibrate TX Gain */
5110 target
= b43_nphy_get_tx_gains(dev
);
5112 if (!b43_nphy_cal_tx_iq_lo(dev
, target
, true, false))
5113 if (b43_nphy_cal_rx_iq(dev
, target
, 2, 0) == 0)
5114 b43_nphy_save_cal(dev
);
5115 } else if (nphy
->mphase_cal_phase_id
== 0)
5116 ;/* N PHY Periodic Calibration with arg 3 */
5118 b43_nphy_restore_cal(dev
);
5122 b43_nphy_tx_pwr_ctrl_coef_setup(dev
);
5123 b43_nphy_tx_power_ctrl(dev
, tx_pwr_state
);
5124 b43_phy_write(dev
, B43_NPHY_TXMACIF_HOLDOFF
, 0x0015);
5125 b43_phy_write(dev
, B43_NPHY_TXMACDELAY
, 0x0320);
5126 if (phy
->rev
>= 3 && phy
->rev
<= 6)
5127 b43_phy_write(dev
, B43_NPHY_PLOAD_CSENSE_EXTLEN
, 0x0014);
5128 b43_nphy_tx_lp_fbw(dev
);
5130 b43_nphy_spur_workaround(dev
);
5135 /**************************************************
5136 * Channel switching ops.
5137 **************************************************/
5139 static void b43_chantab_phy_upload(struct b43_wldev
*dev
,
5140 const struct b43_phy_n_sfo_cfg
*e
)
5142 b43_phy_write(dev
, B43_NPHY_BW1A
, e
->phy_bw1a
);
5143 b43_phy_write(dev
, B43_NPHY_BW2
, e
->phy_bw2
);
5144 b43_phy_write(dev
, B43_NPHY_BW3
, e
->phy_bw3
);
5145 b43_phy_write(dev
, B43_NPHY_BW4
, e
->phy_bw4
);
5146 b43_phy_write(dev
, B43_NPHY_BW5
, e
->phy_bw5
);
5147 b43_phy_write(dev
, B43_NPHY_BW6
, e
->phy_bw6
);
5150 /* http://bcm-v4.sipsolutions.net/802.11/PmuSpurAvoid */
5151 static void b43_nphy_pmu_spur_avoid(struct b43_wldev
*dev
, bool avoid
)
5153 switch (dev
->dev
->bus_type
) {
5154 #ifdef CONFIG_B43_BCMA
5156 bcma_pmu_spuravoid_pllupdate(&dev
->dev
->bdev
->bus
->drv_cc
,
5160 #ifdef CONFIG_B43_SSB
5162 ssb_pmu_spuravoid_pllupdate(&dev
->dev
->sdev
->bus
->chipco
,
5169 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ChanspecSetup */
5170 static void b43_nphy_channel_setup(struct b43_wldev
*dev
,
5171 const struct b43_phy_n_sfo_cfg
*e
,
5172 struct ieee80211_channel
*new_channel
)
5174 struct b43_phy
*phy
= &dev
->phy
;
5175 struct b43_phy_n
*nphy
= dev
->phy
.n
;
5176 int ch
= new_channel
->hw_value
;
5182 b43_phy_read(dev
, B43_NPHY_BANDCTL
) & B43_NPHY_BANDCTL_5GHZ
;
5183 if (new_channel
->band
== IEEE80211_BAND_5GHZ
&& !old_band_5ghz
) {
5184 tmp32
= b43_read32(dev
, B43_MMIO_PSM_PHY_HDR
);
5185 b43_write32(dev
, B43_MMIO_PSM_PHY_HDR
, tmp32
| 4);
5186 b43_phy_set(dev
, B43_PHY_B_BBCFG
, 0xC000);
5187 b43_write32(dev
, B43_MMIO_PSM_PHY_HDR
, tmp32
);
5188 b43_phy_set(dev
, B43_NPHY_BANDCTL
, B43_NPHY_BANDCTL_5GHZ
);
5189 } else if (new_channel
->band
== IEEE80211_BAND_2GHZ
&& old_band_5ghz
) {
5190 b43_phy_mask(dev
, B43_NPHY_BANDCTL
, ~B43_NPHY_BANDCTL_5GHZ
);
5191 tmp32
= b43_read32(dev
, B43_MMIO_PSM_PHY_HDR
);
5192 b43_write32(dev
, B43_MMIO_PSM_PHY_HDR
, tmp32
| 4);
5193 b43_phy_mask(dev
, B43_PHY_B_BBCFG
, 0x3FFF);
5194 b43_write32(dev
, B43_MMIO_PSM_PHY_HDR
, tmp32
);
5197 b43_chantab_phy_upload(dev
, e
);
5199 if (new_channel
->hw_value
== 14) {
5200 b43_nphy_classifier(dev
, 2, 0);
5201 b43_phy_set(dev
, B43_PHY_B_TEST
, 0x0800);
5203 b43_nphy_classifier(dev
, 2, 2);
5204 if (new_channel
->band
== IEEE80211_BAND_2GHZ
)
5205 b43_phy_mask(dev
, B43_PHY_B_TEST
, ~0x840);
5208 if (!nphy
->txpwrctrl
)
5209 b43_nphy_tx_power_fix(dev
);
5211 if (dev
->phy
.rev
< 3)
5212 b43_nphy_adjust_lna_gain_table(dev
);
5214 b43_nphy_tx_lp_fbw(dev
);
5216 if (dev
->phy
.rev
>= 3 &&
5217 dev
->phy
.n
->spur_avoid
!= B43_SPUR_AVOID_DISABLE
) {
5219 if (dev
->phy
.n
->spur_avoid
== B43_SPUR_AVOID_FORCE
) {
5221 } else if (!b43_channel_type_is_40mhz(phy
->channel_type
)) {
5222 if ((ch
>= 5 && ch
<= 8) || ch
== 13 || ch
== 14)
5224 } else { /* 40MHz */
5225 if (nphy
->aband_spurwar_en
&&
5226 (ch
== 38 || ch
== 102 || ch
== 118))
5227 avoid
= dev
->dev
->chip_id
== 0x4716;
5230 b43_nphy_pmu_spur_avoid(dev
, avoid
);
5232 if (dev
->dev
->chip_id
== 43222 || dev
->dev
->chip_id
== 43224 ||
5233 dev
->dev
->chip_id
== 43225) {
5234 b43_write16(dev
, B43_MMIO_TSF_CLK_FRAC_LOW
,
5235 avoid
? 0x5341 : 0x8889);
5236 b43_write16(dev
, B43_MMIO_TSF_CLK_FRAC_HIGH
, 0x8);
5239 if (dev
->phy
.rev
== 3 || dev
->phy
.rev
== 4)
5240 ; /* TODO: reset PLL */
5243 b43_phy_set(dev
, B43_NPHY_BBCFG
, B43_NPHY_BBCFG_RSTRX
);
5245 b43_phy_mask(dev
, B43_NPHY_BBCFG
,
5246 ~B43_NPHY_BBCFG_RSTRX
& 0xFFFF);
5248 b43_nphy_reset_cca(dev
);
5250 /* wl sets useless phy_isspuravoid here */
5253 b43_phy_write(dev
, B43_NPHY_NDATAT_DUP40
, 0x3830);
5256 b43_nphy_spur_workaround(dev
);
5259 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetChanspec */
5260 static int b43_nphy_set_channel(struct b43_wldev
*dev
,
5261 struct ieee80211_channel
*channel
,
5262 enum nl80211_channel_type channel_type
)
5264 struct b43_phy
*phy
= &dev
->phy
;
5266 const struct b43_nphy_channeltab_entry_rev2
*tabent_r2
= NULL
;
5267 const struct b43_nphy_channeltab_entry_rev3
*tabent_r3
= NULL
;
5271 if (dev
->phy
.rev
>= 3) {
5272 tabent_r3
= b43_nphy_get_chantabent_rev3(dev
,
5273 channel
->center_freq
);
5277 tabent_r2
= b43_nphy_get_chantabent_rev2(dev
,
5283 /* Channel is set later in common code, but we need to set it on our
5284 own to let this function's subcalls work properly. */
5285 phy
->channel
= channel
->hw_value
;
5286 phy
->channel_freq
= channel
->center_freq
;
5288 if (b43_channel_type_is_40mhz(phy
->channel_type
) !=
5289 b43_channel_type_is_40mhz(channel_type
))
5290 ; /* TODO: BMAC BW Set (channel_type) */
5292 if (channel_type
== NL80211_CHAN_HT40PLUS
)
5293 b43_phy_set(dev
, B43_NPHY_RXCTL
,
5294 B43_NPHY_RXCTL_BSELU20
);
5295 else if (channel_type
== NL80211_CHAN_HT40MINUS
)
5296 b43_phy_mask(dev
, B43_NPHY_RXCTL
,
5297 ~B43_NPHY_RXCTL_BSELU20
);
5299 if (dev
->phy
.rev
>= 3) {
5300 tmp
= (channel
->band
== IEEE80211_BAND_5GHZ
) ? 4 : 0;
5301 b43_radio_maskset(dev
, 0x08, 0xFFFB, tmp
);
5302 b43_radio_2056_setup(dev
, tabent_r3
);
5303 b43_nphy_channel_setup(dev
, &(tabent_r3
->phy_regs
), channel
);
5305 tmp
= (channel
->band
== IEEE80211_BAND_5GHZ
) ? 0x0020 : 0x0050;
5306 b43_radio_maskset(dev
, B2055_MASTER1
, 0xFF8F, tmp
);
5307 b43_radio_2055_setup(dev
, tabent_r2
);
5308 b43_nphy_channel_setup(dev
, &(tabent_r2
->phy_regs
), channel
);
5314 /**************************************************
5316 **************************************************/
5318 static int b43_nphy_op_allocate(struct b43_wldev
*dev
)
5320 struct b43_phy_n
*nphy
;
5322 nphy
= kzalloc(sizeof(*nphy
), GFP_KERNEL
);
5330 static void b43_nphy_op_prepare_structs(struct b43_wldev
*dev
)
5332 struct b43_phy
*phy
= &dev
->phy
;
5333 struct b43_phy_n
*nphy
= phy
->n
;
5334 struct ssb_sprom
*sprom
= dev
->dev
->bus_sprom
;
5336 memset(nphy
, 0, sizeof(*nphy
));
5338 nphy
->hang_avoid
= (phy
->rev
== 3 || phy
->rev
== 4);
5339 nphy
->spur_avoid
= (phy
->rev
>= 3) ?
5340 B43_SPUR_AVOID_AUTO
: B43_SPUR_AVOID_DISABLE
;
5341 nphy
->init_por
= true;
5342 nphy
->gain_boost
= true; /* this way we follow wl, assume it is true */
5343 nphy
->txrx_chain
= 2; /* sth different than 0 and 1 for now */
5344 nphy
->phyrxchain
= 3; /* to avoid b43_nphy_set_rx_core_state like wl */
5345 nphy
->perical
= 2; /* avoid additional rssi cal on init (like wl) */
5346 /* 128 can mean disabled-by-default state of TX pwr ctl. Max value is
5347 * 0x7f == 127 and we check for 128 when restoring TX pwr ctl. */
5348 nphy
->tx_pwr_idx
[0] = 128;
5349 nphy
->tx_pwr_idx
[1] = 128;
5351 /* Hardware TX power control and 5GHz power gain */
5352 nphy
->txpwrctrl
= false;
5353 nphy
->pwg_gain_5ghz
= false;
5354 if (dev
->phy
.rev
>= 3 ||
5355 (dev
->dev
->board_vendor
== PCI_VENDOR_ID_APPLE
&&
5356 (dev
->dev
->core_rev
== 11 || dev
->dev
->core_rev
== 12))) {
5357 nphy
->txpwrctrl
= true;
5358 nphy
->pwg_gain_5ghz
= true;
5359 } else if (sprom
->revision
>= 4) {
5360 if (dev
->phy
.rev
>= 2 &&
5361 (sprom
->boardflags2_lo
& B43_BFL2_TXPWRCTRL_EN
)) {
5362 nphy
->txpwrctrl
= true;
5363 #ifdef CONFIG_B43_SSB
5364 if (dev
->dev
->bus_type
== B43_BUS_SSB
&&
5365 dev
->dev
->sdev
->bus
->bustype
== SSB_BUSTYPE_PCI
) {
5366 struct pci_dev
*pdev
=
5367 dev
->dev
->sdev
->bus
->host_pci
;
5368 if (pdev
->device
== 0x4328 ||
5369 pdev
->device
== 0x432a)
5370 nphy
->pwg_gain_5ghz
= true;
5373 } else if (sprom
->boardflags2_lo
& B43_BFL2_5G_PWRGAIN
) {
5374 nphy
->pwg_gain_5ghz
= true;
5378 if (dev
->phy
.rev
>= 3) {
5379 nphy
->ipa2g_on
= sprom
->fem
.ghz2
.extpa_gain
== 2;
5380 nphy
->ipa5g_on
= sprom
->fem
.ghz5
.extpa_gain
== 2;
5383 nphy
->init_por
= true;
5386 static void b43_nphy_op_free(struct b43_wldev
*dev
)
5388 struct b43_phy
*phy
= &dev
->phy
;
5389 struct b43_phy_n
*nphy
= phy
->n
;
5395 static int b43_nphy_op_init(struct b43_wldev
*dev
)
5397 return b43_phy_initn(dev
);
5400 static inline void check_phyreg(struct b43_wldev
*dev
, u16 offset
)
5403 if ((offset
& B43_PHYROUTE
) == B43_PHYROUTE_OFDM_GPHY
) {
5404 /* OFDM registers are onnly available on A/G-PHYs */
5405 b43err(dev
->wl
, "Invalid OFDM PHY access at "
5406 "0x%04X on N-PHY\n", offset
);
5409 if ((offset
& B43_PHYROUTE
) == B43_PHYROUTE_EXT_GPHY
) {
5410 /* Ext-G registers are only available on G-PHYs */
5411 b43err(dev
->wl
, "Invalid EXT-G PHY access at "
5412 "0x%04X on N-PHY\n", offset
);
5415 #endif /* B43_DEBUG */
5418 static u16
b43_nphy_op_read(struct b43_wldev
*dev
, u16 reg
)
5420 check_phyreg(dev
, reg
);
5421 b43_write16(dev
, B43_MMIO_PHY_CONTROL
, reg
);
5422 return b43_read16(dev
, B43_MMIO_PHY_DATA
);
5425 static void b43_nphy_op_write(struct b43_wldev
*dev
, u16 reg
, u16 value
)
5427 check_phyreg(dev
, reg
);
5428 b43_write16(dev
, B43_MMIO_PHY_CONTROL
, reg
);
5429 b43_write16(dev
, B43_MMIO_PHY_DATA
, value
);
5432 static void b43_nphy_op_maskset(struct b43_wldev
*dev
, u16 reg
, u16 mask
,
5435 check_phyreg(dev
, reg
);
5436 b43_write16(dev
, B43_MMIO_PHY_CONTROL
, reg
);
5437 b43_maskset16(dev
, B43_MMIO_PHY_DATA
, mask
, set
);
5440 static u16
b43_nphy_op_radio_read(struct b43_wldev
*dev
, u16 reg
)
5442 /* Register 1 is a 32-bit register. */
5443 B43_WARN_ON(reg
== 1);
5444 /* N-PHY needs 0x100 for read access */
5447 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, reg
);
5448 return b43_read16(dev
, B43_MMIO_RADIO_DATA_LOW
);
5451 static void b43_nphy_op_radio_write(struct b43_wldev
*dev
, u16 reg
, u16 value
)
5453 /* Register 1 is a 32-bit register. */
5454 B43_WARN_ON(reg
== 1);
5456 b43_write16(dev
, B43_MMIO_RADIO_CONTROL
, reg
);
5457 b43_write16(dev
, B43_MMIO_RADIO_DATA_LOW
, value
);
5460 /* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
5461 static void b43_nphy_op_software_rfkill(struct b43_wldev
*dev
,
5464 if (b43_read32(dev
, B43_MMIO_MACCTL
) & B43_MACCTL_ENABLED
)
5465 b43err(dev
->wl
, "MAC not suspended\n");
5468 b43_phy_mask(dev
, B43_NPHY_RFCTL_CMD
,
5469 ~B43_NPHY_RFCTL_CMD_CHIP0PU
);
5470 if (dev
->phy
.rev
>= 7) {
5472 } else if (dev
->phy
.rev
>= 3) {
5473 b43_radio_mask(dev
, 0x09, ~0x2);
5475 b43_radio_write(dev
, 0x204D, 0);
5476 b43_radio_write(dev
, 0x2053, 0);
5477 b43_radio_write(dev
, 0x2058, 0);
5478 b43_radio_write(dev
, 0x205E, 0);
5479 b43_radio_mask(dev
, 0x2062, ~0xF0);
5480 b43_radio_write(dev
, 0x2064, 0);
5482 b43_radio_write(dev
, 0x304D, 0);
5483 b43_radio_write(dev
, 0x3053, 0);
5484 b43_radio_write(dev
, 0x3058, 0);
5485 b43_radio_write(dev
, 0x305E, 0);
5486 b43_radio_mask(dev
, 0x3062, ~0xF0);
5487 b43_radio_write(dev
, 0x3064, 0);
5490 if (dev
->phy
.rev
>= 7) {
5491 b43_radio_2057_init(dev
);
5492 b43_switch_channel(dev
, dev
->phy
.channel
);
5493 } else if (dev
->phy
.rev
>= 3) {
5494 b43_radio_init2056(dev
);
5495 b43_switch_channel(dev
, dev
->phy
.channel
);
5497 b43_radio_init2055(dev
);
5502 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Anacore */
5503 static void b43_nphy_op_switch_analog(struct b43_wldev
*dev
, bool on
)
5505 u16 override
= on
? 0x0 : 0x7FFF;
5506 u16 core
= on
? 0xD : 0x00FD;
5508 if (dev
->phy
.rev
>= 3) {
5510 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, core
);
5511 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, override
);
5512 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, core
);
5513 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, override
);
5515 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER1
, override
);
5516 b43_phy_write(dev
, B43_NPHY_AFECTL_C1
, core
);
5517 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, override
);
5518 b43_phy_write(dev
, B43_NPHY_AFECTL_C2
, core
);
5521 b43_phy_write(dev
, B43_NPHY_AFECTL_OVER
, override
);
5525 static int b43_nphy_op_switch_channel(struct b43_wldev
*dev
,
5526 unsigned int new_channel
)
5528 struct ieee80211_channel
*channel
= dev
->wl
->hw
->conf
.chandef
.chan
;
5529 enum nl80211_channel_type channel_type
=
5530 cfg80211_get_chandef_type(&dev
->wl
->hw
->conf
.chandef
);
5532 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
) {
5533 if ((new_channel
< 1) || (new_channel
> 14))
5536 if (new_channel
> 200)
5540 return b43_nphy_set_channel(dev
, channel
, channel_type
);
5543 static unsigned int b43_nphy_op_get_default_chan(struct b43_wldev
*dev
)
5545 if (b43_current_band(dev
->wl
) == IEEE80211_BAND_2GHZ
)
5550 const struct b43_phy_operations b43_phyops_n
= {
5551 .allocate
= b43_nphy_op_allocate
,
5552 .free
= b43_nphy_op_free
,
5553 .prepare_structs
= b43_nphy_op_prepare_structs
,
5554 .init
= b43_nphy_op_init
,
5555 .phy_read
= b43_nphy_op_read
,
5556 .phy_write
= b43_nphy_op_write
,
5557 .phy_maskset
= b43_nphy_op_maskset
,
5558 .radio_read
= b43_nphy_op_radio_read
,
5559 .radio_write
= b43_nphy_op_radio_write
,
5560 .software_rfkill
= b43_nphy_op_software_rfkill
,
5561 .switch_analog
= b43_nphy_op_switch_analog
,
5562 .switch_channel
= b43_nphy_op_switch_channel
,
5563 .get_default_chan
= b43_nphy_op_get_default_chan
,
5564 .recalc_txpower
= b43_nphy_op_recalc_txpower
,
5565 .adjust_txpower
= b43_nphy_op_adjust_txpower
,