2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/kernel.h>
17 #include <linux/delay.h>
18 #include <linux/bitops.h>
20 #include <brcm_hw_ids.h>
21 #include <chipcommon.h>
27 #include "phy_radio.h"
31 #define VALID_N_RADIO(radioid) ((radioid == BCM2055_ID) || \
32 (radioid == BCM2056_ID) || \
33 (radioid == BCM2057_ID))
35 #define VALID_LCN_RADIO(radioid) (radioid == BCM2064_ID)
37 #define VALID_RADIO(pi, radioid) ( \
38 (ISNPHY(pi) ? VALID_N_RADIO(radioid) : false) || \
39 (ISLCNPHY(pi) ? VALID_LCN_RADIO(radioid) : false))
41 /* basic mux operation - can be optimized on several architectures */
42 #define MUX(pred, true, false) ((pred) ? (true) : (false))
44 /* modulo inc/dec - assumes x E [0, bound - 1] */
45 #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
47 /* modulo inc/dec, bound = 2^k */
48 #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
49 #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
51 struct chan_info_basic
{
56 static const struct chan_info_basic chan_info_all
[] = {
115 static const u8 ofdm_rate_lookup
[] = {
127 #define PHY_WREG_LIMIT 24
129 void wlc_phyreg_enter(struct brcms_phy_pub
*pih
)
131 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
132 wlapi_bmac_ucode_wake_override_phyreg_set(pi
->sh
->physhim
);
135 void wlc_phyreg_exit(struct brcms_phy_pub
*pih
)
137 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
138 wlapi_bmac_ucode_wake_override_phyreg_clear(pi
->sh
->physhim
);
141 void wlc_radioreg_enter(struct brcms_phy_pub
*pih
)
143 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
144 wlapi_bmac_mctrl(pi
->sh
->physhim
, MCTL_LOCK_RADIO
, MCTL_LOCK_RADIO
);
149 void wlc_radioreg_exit(struct brcms_phy_pub
*pih
)
151 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
153 (void)bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
155 wlapi_bmac_mctrl(pi
->sh
->physhim
, MCTL_LOCK_RADIO
, 0);
158 u16
read_radio_reg(struct brcms_phy
*pi
, u16 addr
)
162 if ((addr
== RADIO_IDCODE
))
165 switch (pi
->pubpi
.phy_type
) {
167 if (!CONF_HAS(PHYTYPE
, PHY_TYPE_N
))
169 if (NREV_GE(pi
->pubpi
.phy_rev
, 7))
170 addr
|= RADIO_2057_READ_OFF
;
172 addr
|= RADIO_2055_READ_OFF
;
176 if (!CONF_HAS(PHYTYPE
, PHY_TYPE_LCN
))
178 addr
|= RADIO_2064_READ_OFF
;
185 if ((D11REV_GE(pi
->sh
->corerev
, 24)) ||
186 (D11REV_IS(pi
->sh
->corerev
, 22)
187 && (pi
->pubpi
.phy_type
!= PHY_TYPE_SSN
))) {
188 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), addr
);
189 data
= bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
191 bcma_wflush16(pi
->d11core
, D11REGOFFS(phy4waddr
), addr
);
192 data
= bcma_read16(pi
->d11core
, D11REGOFFS(phy4wdatalo
));
199 void write_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
201 if ((D11REV_GE(pi
->sh
->corerev
, 24)) ||
202 (D11REV_IS(pi
->sh
->corerev
, 22)
203 && (pi
->pubpi
.phy_type
!= PHY_TYPE_SSN
))) {
205 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), addr
);
206 bcma_write16(pi
->d11core
, D11REGOFFS(radioregdata
), val
);
208 bcma_wflush16(pi
->d11core
, D11REGOFFS(phy4waddr
), addr
);
209 bcma_write16(pi
->d11core
, D11REGOFFS(phy4wdatalo
), val
);
212 if (++pi
->phy_wreg
>= pi
->phy_wreg_limit
) {
213 (void)bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
218 static u32
read_radio_id(struct brcms_phy
*pi
)
222 if (D11REV_GE(pi
->sh
->corerev
, 24)) {
225 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 0);
226 b0
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
227 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 1);
228 b1
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
229 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 2);
230 b2
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
232 id
= ((b0
& 0xf) << 28) | (((b2
<< 8) | b1
) << 12) | ((b0
>> 4)
235 bcma_wflush16(pi
->d11core
, D11REGOFFS(phy4waddr
), RADIO_IDCODE
);
236 id
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(phy4wdatalo
));
237 id
|= (u32
) bcma_read16(pi
->d11core
,
238 D11REGOFFS(phy4wdatahi
)) << 16;
244 void and_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
248 rval
= read_radio_reg(pi
, addr
);
249 write_radio_reg(pi
, addr
, (rval
& val
));
252 void or_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
256 rval
= read_radio_reg(pi
, addr
);
257 write_radio_reg(pi
, addr
, (rval
| val
));
260 void xor_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
)
264 rval
= read_radio_reg(pi
, addr
);
265 write_radio_reg(pi
, addr
, (rval
^ mask
));
268 void mod_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
, u16 val
)
272 rval
= read_radio_reg(pi
, addr
);
273 write_radio_reg(pi
, addr
, (rval
& ~mask
) | (val
& mask
));
276 void write_phy_channel_reg(struct brcms_phy
*pi
, uint val
)
278 bcma_write16(pi
->d11core
, D11REGOFFS(phychannel
), val
);
281 u16
read_phy_reg(struct brcms_phy
*pi
, u16 addr
)
283 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
286 return bcma_read16(pi
->d11core
, D11REGOFFS(phyregdata
));
289 void write_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
291 #ifdef CONFIG_BCM47XX
292 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
293 bcma_write16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
295 (void)bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
297 bcma_write32(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
| (val
<< 16));
298 if (++pi
->phy_wreg
>= pi
->phy_wreg_limit
) {
300 (void)bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
305 void and_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
307 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
308 bcma_mask16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
312 void or_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
314 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
315 bcma_set16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
319 void mod_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
, u16 val
)
322 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
323 bcma_maskset16(pi
->d11core
, D11REGOFFS(phyregdata
), ~mask
, val
);
327 static void wlc_set_phy_uninitted(struct brcms_phy
*pi
)
331 pi
->initialized
= false;
334 pi
->nrssi_table_delta
= 0x7fffffff;
336 pi
->mintxbias
= 0xffff;
339 pi
->phy_spuravoid
= SPURAVOID_DISABLE
;
341 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)
342 && NREV_LT(pi
->pubpi
.phy_rev
, 7))
343 pi
->phy_spuravoid
= SPURAVOID_AUTO
;
345 pi
->nphy_papd_skip
= 0;
346 pi
->nphy_papd_epsilon_offset
[0] = 0xf588;
347 pi
->nphy_papd_epsilon_offset
[1] = 0xf588;
348 pi
->nphy_txpwr_idx
[0] = 128;
349 pi
->nphy_txpwr_idx
[1] = 128;
350 pi
->nphy_txpwrindex
[0].index_internal
= 40;
351 pi
->nphy_txpwrindex
[1].index_internal
= 40;
354 pi
->phy_spuravoid
= SPURAVOID_AUTO
;
356 pi
->radiopwr
= 0xffff;
357 for (i
= 0; i
< STATIC_NUM_RF
; i
++) {
358 for (j
= 0; j
< STATIC_NUM_BB
; j
++)
359 pi
->stats_11b_txpower
[i
][j
] = -1;
363 struct shared_phy
*wlc_phy_shared_attach(struct shared_phy_params
*shp
)
365 struct shared_phy
*sh
;
367 sh
= kzalloc(sizeof(struct shared_phy
), GFP_ATOMIC
);
372 sh
->physhim
= shp
->physhim
;
373 sh
->unit
= shp
->unit
;
374 sh
->corerev
= shp
->corerev
;
378 sh
->chip
= shp
->chip
;
379 sh
->chiprev
= shp
->chiprev
;
380 sh
->chippkg
= shp
->chippkg
;
381 sh
->sromrev
= shp
->sromrev
;
382 sh
->boardtype
= shp
->boardtype
;
383 sh
->boardrev
= shp
->boardrev
;
384 sh
->boardflags
= shp
->boardflags
;
385 sh
->boardflags2
= shp
->boardflags2
;
387 sh
->fast_timer
= PHY_SW_TIMER_FAST
;
388 sh
->slow_timer
= PHY_SW_TIMER_SLOW
;
389 sh
->glacial_timer
= PHY_SW_TIMER_GLACIAL
;
391 sh
->rssi_mode
= RSSI_ANT_MERGE_MAX
;
396 static void wlc_phy_timercb_phycal(struct brcms_phy
*pi
)
400 if (PHY_PERICAL_MPHASE_PENDING(pi
)) {
402 wlc_phy_cal_perical_mphase_reset(pi
);
406 if (SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)) {
409 wlc_phy_cal_perical_mphase_restart(pi
);
411 wlc_phy_cal_perical_nphy_run(pi
, PHY_PERICAL_AUTO
);
412 wlapi_add_timer(pi
->phycal_timer
, delay
, 0);
418 static u32
wlc_phy_get_radio_ver(struct brcms_phy
*pi
)
422 ver
= read_radio_id(pi
);
427 struct brcms_phy_pub
*
428 wlc_phy_attach(struct shared_phy
*sh
, struct bcma_device
*d11core
,
429 int bandtype
, struct wiphy
*wiphy
)
431 struct brcms_phy
*pi
;
437 if (D11REV_IS(sh
->corerev
, 4))
438 sflags
= SISF_2G_PHY
| SISF_5G_PHY
;
440 sflags
= bcma_aread32(d11core
, BCMA_IOST
);
442 if (bandtype
== BRCM_BAND_5G
) {
443 if ((sflags
& (SISF_5G_PHY
| SISF_DB_PHY
)) == 0)
448 if ((sflags
& SISF_DB_PHY
) && pi
) {
449 wlapi_bmac_corereset(pi
->sh
->physhim
, pi
->pubpi
.coreflags
);
451 return &pi
->pubpi_ro
;
454 pi
= kzalloc(sizeof(struct brcms_phy
), GFP_ATOMIC
);
458 pi
->d11core
= d11core
;
460 pi
->phy_init_por
= true;
461 pi
->phy_wreg_limit
= PHY_WREG_LIMIT
;
463 pi
->txpwr_percent
= 100;
465 pi
->do_initcal
= true;
467 pi
->phycal_tempdelta
= 0;
469 if (bandtype
== BRCM_BAND_2G
&& (sflags
& SISF_2G_PHY
))
470 pi
->pubpi
.coreflags
= SICF_GMODE
;
472 wlapi_bmac_corereset(pi
->sh
->physhim
, pi
->pubpi
.coreflags
);
473 phyversion
= bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
475 pi
->pubpi
.phy_type
= PHY_TYPE(phyversion
);
476 pi
->pubpi
.phy_rev
= phyversion
& PV_PV_MASK
;
478 if (pi
->pubpi
.phy_type
== PHY_TYPE_LCNXN
) {
479 pi
->pubpi
.phy_type
= PHY_TYPE_N
;
480 pi
->pubpi
.phy_rev
+= LCNXN_BASEREV
;
482 pi
->pubpi
.phy_corenum
= PHY_CORE_NUM_2
;
483 pi
->pubpi
.ana_rev
= (phyversion
& PV_AV_MASK
) >> PV_AV_SHIFT
;
485 if (pi
->pubpi
.phy_type
!= PHY_TYPE_N
&&
486 pi
->pubpi
.phy_type
!= PHY_TYPE_LCN
)
489 if (bandtype
== BRCM_BAND_5G
) {
492 } else if (!ISNPHY(pi
) && !ISLCNPHY(pi
)) {
496 wlc_phy_anacore((struct brcms_phy_pub
*) pi
, ON
);
498 idcode
= wlc_phy_get_radio_ver(pi
);
500 (idcode
& IDCODE_ID_MASK
) >> IDCODE_ID_SHIFT
;
502 (idcode
& IDCODE_REV_MASK
) >> IDCODE_REV_SHIFT
;
504 (idcode
& IDCODE_VER_MASK
) >> IDCODE_VER_SHIFT
;
505 if (!VALID_RADIO(pi
, pi
->pubpi
.radioid
))
508 wlc_phy_switch_radio((struct brcms_phy_pub
*) pi
, OFF
);
510 wlc_set_phy_uninitted(pi
);
512 pi
->bw
= WL_CHANSPEC_BW_20
;
513 pi
->radio_chanspec
= (bandtype
== BRCM_BAND_2G
) ?
514 ch20mhz_chspec(1) : ch20mhz_chspec(36);
516 pi
->rxiq_samps
= PHY_NOISE_SAMPLE_LOG_NUM_NPHY
;
517 pi
->rxiq_antsel
= ANT_RX_DIV_DEF
;
519 pi
->watchdog_override
= true;
521 pi
->cal_type_override
= PHY_PERICAL_AUTO
;
523 pi
->nphy_saved_noisevars
.bufcount
= 0;
526 pi
->min_txpower
= PHY_TXPWR_MIN_NPHY
;
528 pi
->min_txpower
= PHY_TXPWR_MIN
;
530 pi
->sh
->phyrxchain
= 0x3;
532 pi
->rx2tx_biasentry
= -1;
534 pi
->phy_txcore_disable_temp
= PHY_CHAIN_TX_DISABLE_TEMP
;
535 pi
->phy_txcore_enable_temp
=
536 PHY_CHAIN_TX_DISABLE_TEMP
- PHY_HYSTERESIS_DELTATEMP
;
537 pi
->phy_tempsense_offset
= 0;
538 pi
->phy_txcore_heatedup
= false;
540 pi
->nphy_lastcal_temp
= -50;
542 pi
->phynoise_polling
= true;
543 if (ISNPHY(pi
) || ISLCNPHY(pi
))
544 pi
->phynoise_polling
= false;
546 for (i
= 0; i
< TXP_NUM_RATES
; i
++) {
547 pi
->txpwr_limit
[i
] = BRCMS_TXPWR_MAX
;
548 pi
->txpwr_env_limit
[i
] = BRCMS_TXPWR_MAX
;
549 pi
->tx_user_target
[i
] = BRCMS_TXPWR_MAX
;
552 pi
->radiopwr_override
= RADIOPWR_OVERRIDE_DEF
;
554 pi
->user_txpwr_at_rfport
= false;
558 pi
->phycal_timer
= wlapi_init_timer(pi
->sh
->physhim
,
559 wlc_phy_timercb_phycal
,
561 if (!pi
->phycal_timer
)
564 if (!wlc_phy_attach_nphy(pi
))
567 } else if (ISLCNPHY(pi
)) {
568 if (!wlc_phy_attach_lcnphy(pi
))
574 pi
->next
= pi
->sh
->phy_head
;
577 memcpy(&pi
->pubpi_ro
, &pi
->pubpi
, sizeof(struct brcms_phy_pub
));
579 return &pi
->pubpi_ro
;
586 void wlc_phy_detach(struct brcms_phy_pub
*pih
)
588 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
594 if (pi
->phycal_timer
) {
595 wlapi_free_timer(pi
->phycal_timer
);
596 pi
->phycal_timer
= NULL
;
599 if (pi
->sh
->phy_head
== pi
)
600 pi
->sh
->phy_head
= pi
->next
;
601 else if (pi
->sh
->phy_head
->next
== pi
)
602 pi
->sh
->phy_head
->next
= NULL
;
604 if (pi
->pi_fptr
.detach
)
605 (pi
->pi_fptr
.detach
)(pi
);
612 wlc_phy_get_phyversion(struct brcms_phy_pub
*pih
, u16
*phytype
, u16
*phyrev
,
613 u16
*radioid
, u16
*radiover
)
615 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
616 *phytype
= (u16
) pi
->pubpi
.phy_type
;
617 *phyrev
= (u16
) pi
->pubpi
.phy_rev
;
618 *radioid
= pi
->pubpi
.radioid
;
619 *radiover
= pi
->pubpi
.radiorev
;
624 bool wlc_phy_get_encore(struct brcms_phy_pub
*pih
)
626 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
627 return pi
->pubpi
.abgphy_encore
;
630 u32
wlc_phy_get_coreflags(struct brcms_phy_pub
*pih
)
632 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
633 return pi
->pubpi
.coreflags
;
636 void wlc_phy_anacore(struct brcms_phy_pub
*pih
, bool on
)
638 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
642 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
643 write_phy_reg(pi
, 0xa6, 0x0d);
644 write_phy_reg(pi
, 0x8f, 0x0);
645 write_phy_reg(pi
, 0xa7, 0x0d);
646 write_phy_reg(pi
, 0xa5, 0x0);
648 write_phy_reg(pi
, 0xa5, 0x0);
651 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
652 write_phy_reg(pi
, 0x8f, 0x07ff);
653 write_phy_reg(pi
, 0xa6, 0x0fd);
654 write_phy_reg(pi
, 0xa5, 0x07ff);
655 write_phy_reg(pi
, 0xa7, 0x0fd);
657 write_phy_reg(pi
, 0xa5, 0x7fff);
660 } else if (ISLCNPHY(pi
)) {
662 and_phy_reg(pi
, 0x43b,
663 ~((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
665 or_phy_reg(pi
, 0x43c,
666 (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
667 or_phy_reg(pi
, 0x43b,
668 (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
673 u32
wlc_phy_clk_bwbits(struct brcms_phy_pub
*pih
)
675 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
677 u32 phy_bw_clkbits
= 0;
679 if (pi
&& (ISNPHY(pi
) || ISLCNPHY(pi
))) {
681 case WL_CHANSPEC_BW_10
:
682 phy_bw_clkbits
= SICF_BW10
;
684 case WL_CHANSPEC_BW_20
:
685 phy_bw_clkbits
= SICF_BW20
;
687 case WL_CHANSPEC_BW_40
:
688 phy_bw_clkbits
= SICF_BW40
;
695 return phy_bw_clkbits
;
698 void wlc_phy_por_inform(struct brcms_phy_pub
*ppi
)
700 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
702 pi
->phy_init_por
= true;
705 void wlc_phy_edcrs_lock(struct brcms_phy_pub
*pih
, bool lock
)
707 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
709 pi
->edcrs_threshold_lock
= lock
;
711 write_phy_reg(pi
, 0x22c, 0x46b);
712 write_phy_reg(pi
, 0x22d, 0x46b);
713 write_phy_reg(pi
, 0x22e, 0x3c0);
714 write_phy_reg(pi
, 0x22f, 0x3c0);
717 void wlc_phy_initcal_enable(struct brcms_phy_pub
*pih
, bool initcal
)
719 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
721 pi
->do_initcal
= initcal
;
724 void wlc_phy_hw_clk_state_upd(struct brcms_phy_pub
*pih
, bool newstate
)
726 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
731 pi
->sh
->clk
= newstate
;
734 void wlc_phy_hw_state_upd(struct brcms_phy_pub
*pih
, bool newstate
)
736 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
741 pi
->sh
->up
= newstate
;
744 void wlc_phy_init(struct brcms_phy_pub
*pih
, u16 chanspec
)
747 void (*phy_init
)(struct brcms_phy
*) = NULL
;
748 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
750 if (pi
->init_in_progress
)
753 pi
->init_in_progress
= true;
755 pi
->radio_chanspec
= chanspec
;
757 mc
= bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
758 if (WARN(mc
& MCTL_EN_MAC
, "HW error MAC running on init"))
761 if (!(pi
->measure_hold
& PHY_HOLD_FOR_SCAN
))
762 pi
->measure_hold
|= PHY_HOLD_FOR_NOT_ASSOC
;
764 if (WARN(!(bcma_aread32(pi
->d11core
, BCMA_IOST
) & SISF_FCLKA
),
765 "HW error SISF_FCLKA\n"))
768 phy_init
= pi
->pi_fptr
.init
;
770 if (phy_init
== NULL
)
773 wlc_phy_anacore(pih
, ON
);
775 if (CHSPEC_BW(pi
->radio_chanspec
) != pi
->bw
)
776 wlapi_bmac_bw_set(pi
->sh
->physhim
,
777 CHSPEC_BW(pi
->radio_chanspec
));
779 pi
->nphy_gain_boost
= true;
781 wlc_phy_switch_radio((struct brcms_phy_pub
*) pi
, ON
);
785 pi
->phy_init_por
= false;
787 if (D11REV_IS(pi
->sh
->corerev
, 11) || D11REV_IS(pi
->sh
->corerev
, 12))
788 wlc_phy_do_dummy_tx(pi
, true, OFF
);
791 wlc_phy_txpower_update_shm(pi
);
793 wlc_phy_ant_rxdiv_set((struct brcms_phy_pub
*) pi
, pi
->sh
->rx_antdiv
);
795 pi
->init_in_progress
= false;
798 void wlc_phy_cal_init(struct brcms_phy_pub
*pih
)
800 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
801 void (*cal_init
)(struct brcms_phy
*) = NULL
;
803 if (WARN((bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) &
804 MCTL_EN_MAC
) != 0, "HW error: MAC enabled during phy cal\n"))
807 if (!pi
->initialized
) {
808 cal_init
= pi
->pi_fptr
.calinit
;
812 pi
->initialized
= true;
816 int wlc_phy_down(struct brcms_phy_pub
*pih
)
818 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
822 && !wlapi_del_timer(pi
->phycal_timer
))
825 pi
->nphy_iqcal_chanspec_2G
= 0;
826 pi
->nphy_iqcal_chanspec_5G
= 0;
832 wlc_phy_table_addr(struct brcms_phy
*pi
, uint tbl_id
, uint tbl_offset
,
833 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
835 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
837 pi
->tbl_data_hi
= tblDataHi
;
838 pi
->tbl_data_lo
= tblDataLo
;
840 if (pi
->sh
->chip
== BCM43224_CHIP_ID
&&
841 pi
->sh
->chiprev
== 1) {
842 pi
->tbl_addr
= tblAddr
;
843 pi
->tbl_save_id
= tbl_id
;
844 pi
->tbl_save_offset
= tbl_offset
;
848 void wlc_phy_table_data_write(struct brcms_phy
*pi
, uint width
, u32 val
)
850 if ((pi
->sh
->chip
== BCM43224_CHIP_ID
) &&
851 (pi
->sh
->chiprev
== 1) &&
852 (pi
->tbl_save_id
== NPHY_TBL_ID_ANTSWCTRLLUT
)) {
853 read_phy_reg(pi
, pi
->tbl_data_lo
);
855 write_phy_reg(pi
, pi
->tbl_addr
,
856 (pi
->tbl_save_id
<< 10) | pi
->tbl_save_offset
);
857 pi
->tbl_save_offset
++;
861 write_phy_reg(pi
, pi
->tbl_data_hi
, (u16
) (val
>> 16));
862 write_phy_reg(pi
, pi
->tbl_data_lo
, (u16
) val
);
864 write_phy_reg(pi
, pi
->tbl_data_lo
, (u16
) val
);
869 wlc_phy_write_table(struct brcms_phy
*pi
, const struct phytbl_info
*ptbl_info
,
870 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
873 uint tbl_id
= ptbl_info
->tbl_id
;
874 uint tbl_offset
= ptbl_info
->tbl_offset
;
875 uint tbl_width
= ptbl_info
->tbl_width
;
876 const u8
*ptbl_8b
= (const u8
*)ptbl_info
->tbl_ptr
;
877 const u16
*ptbl_16b
= (const u16
*)ptbl_info
->tbl_ptr
;
878 const u32
*ptbl_32b
= (const u32
*)ptbl_info
->tbl_ptr
;
880 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
882 for (idx
= 0; idx
< ptbl_info
->tbl_len
; idx
++) {
884 if ((pi
->sh
->chip
== BCM43224_CHIP_ID
) &&
885 (pi
->sh
->chiprev
== 1) &&
886 (tbl_id
== NPHY_TBL_ID_ANTSWCTRLLUT
)) {
887 read_phy_reg(pi
, tblDataLo
);
889 write_phy_reg(pi
, tblAddr
,
890 (tbl_id
<< 10) | (tbl_offset
+ idx
));
893 if (tbl_width
== 32) {
894 write_phy_reg(pi
, tblDataHi
,
895 (u16
) (ptbl_32b
[idx
] >> 16));
896 write_phy_reg(pi
, tblDataLo
, (u16
) ptbl_32b
[idx
]);
897 } else if (tbl_width
== 16) {
898 write_phy_reg(pi
, tblDataLo
, ptbl_16b
[idx
]);
900 write_phy_reg(pi
, tblDataLo
, ptbl_8b
[idx
]);
906 wlc_phy_read_table(struct brcms_phy
*pi
, const struct phytbl_info
*ptbl_info
,
907 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
910 uint tbl_id
= ptbl_info
->tbl_id
;
911 uint tbl_offset
= ptbl_info
->tbl_offset
;
912 uint tbl_width
= ptbl_info
->tbl_width
;
913 u8
*ptbl_8b
= (u8
*)ptbl_info
->tbl_ptr
;
914 u16
*ptbl_16b
= (u16
*)ptbl_info
->tbl_ptr
;
915 u32
*ptbl_32b
= (u32
*)ptbl_info
->tbl_ptr
;
917 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
919 for (idx
= 0; idx
< ptbl_info
->tbl_len
; idx
++) {
921 if ((pi
->sh
->chip
== BCM43224_CHIP_ID
) &&
922 (pi
->sh
->chiprev
== 1)) {
923 (void)read_phy_reg(pi
, tblDataLo
);
925 write_phy_reg(pi
, tblAddr
,
926 (tbl_id
<< 10) | (tbl_offset
+ idx
));
929 if (tbl_width
== 32) {
930 ptbl_32b
[idx
] = read_phy_reg(pi
, tblDataLo
);
931 ptbl_32b
[idx
] |= (read_phy_reg(pi
, tblDataHi
) << 16);
932 } else if (tbl_width
== 16) {
933 ptbl_16b
[idx
] = read_phy_reg(pi
, tblDataLo
);
935 ptbl_8b
[idx
] = (u8
) read_phy_reg(pi
, tblDataLo
);
941 wlc_phy_init_radio_regs_allbands(struct brcms_phy
*pi
,
942 struct radio_20xx_regs
*radioregs
)
947 if (radioregs
[i
].do_init
)
948 write_radio_reg(pi
, radioregs
[i
].address
,
949 (u16
) radioregs
[i
].init
);
952 } while (radioregs
[i
].address
!= 0xffff);
958 wlc_phy_init_radio_regs(struct brcms_phy
*pi
,
959 const struct radio_regs
*radioregs
,
966 if (CHSPEC_IS5G(pi
->radio_chanspec
)) {
967 if (radioregs
[i
].do_init_a
) {
970 address
| core_offset
,
971 (u16
) radioregs
[i
].init_a
);
972 if (ISNPHY(pi
) && (++count
% 4 == 0))
973 BRCMS_PHY_WAR_PR51571(pi
);
976 if (radioregs
[i
].do_init_g
) {
979 address
| core_offset
,
980 (u16
) radioregs
[i
].init_g
);
981 if (ISNPHY(pi
) && (++count
% 4 == 0))
982 BRCMS_PHY_WAR_PR51571(pi
);
987 } while (radioregs
[i
].address
!= 0xffff);
992 void wlc_phy_do_dummy_tx(struct brcms_phy
*pi
, bool ofdm
, bool pa_on
)
994 #define DUMMY_PKT_LEN 20
995 struct bcma_device
*core
= pi
->d11core
;
997 u8 ofdmpkt
[DUMMY_PKT_LEN
] = {
998 0xcc, 0x01, 0x02, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
999 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
1001 u8 cckpkt
[DUMMY_PKT_LEN
] = {
1002 0x6e, 0x84, 0x0b, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
1003 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
1007 dummypkt
= (u32
*) (ofdm
? ofdmpkt
: cckpkt
);
1008 wlapi_bmac_write_template_ram(pi
->sh
->physhim
, 0, DUMMY_PKT_LEN
,
1011 bcma_write16(core
, D11REGOFFS(xmtsel
), 0);
1013 if (D11REV_GE(pi
->sh
->corerev
, 11))
1014 bcma_write16(core
, D11REGOFFS(wepctl
), 0x100);
1016 bcma_write16(core
, D11REGOFFS(wepctl
), 0);
1018 bcma_write16(core
, D11REGOFFS(txe_phyctl
),
1019 (ofdm
? 1 : 0) | PHY_TXC_ANT_0
);
1020 if (ISNPHY(pi
) || ISLCNPHY(pi
))
1021 bcma_write16(core
, D11REGOFFS(txe_phyctl1
), 0x1A02);
1023 bcma_write16(core
, D11REGOFFS(txe_wm_0
), 0);
1024 bcma_write16(core
, D11REGOFFS(txe_wm_1
), 0);
1026 bcma_write16(core
, D11REGOFFS(xmttplatetxptr
), 0);
1027 bcma_write16(core
, D11REGOFFS(xmttxcnt
), DUMMY_PKT_LEN
);
1029 bcma_write16(core
, D11REGOFFS(xmtsel
),
1030 ((8 << 8) | (1 << 5) | (1 << 2) | 2));
1032 bcma_write16(core
, D11REGOFFS(txe_ctl
), 0);
1036 wlc_phy_pa_override_nphy(pi
, OFF
);
1039 if (ISNPHY(pi
) || ISLCNPHY(pi
))
1040 bcma_write16(core
, D11REGOFFS(txe_aux
), 0xD0);
1042 bcma_write16(core
, D11REGOFFS(txe_aux
), ((1 << 5) | (1 << 4)));
1044 (void)bcma_read16(core
, D11REGOFFS(txe_aux
));
1047 count
= ofdm
? 30 : 250;
1048 while ((i
++ < count
)
1049 && (bcma_read16(core
, D11REGOFFS(txe_status
)) & (1 << 7)))
1054 while ((i
++ < 10) &&
1055 ((bcma_read16(core
, D11REGOFFS(txe_status
)) & (1 << 10)) == 0))
1060 while ((i
++ < 10) &&
1061 ((bcma_read16(core
, D11REGOFFS(ifsstat
)) & (1 << 8))))
1066 wlc_phy_pa_override_nphy(pi
, ON
);
1070 void wlc_phy_hold_upd(struct brcms_phy_pub
*pih
, u32 id
, bool set
)
1072 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1075 mboolset(pi
->measure_hold
, id
);
1077 mboolclr(pi
->measure_hold
, id
);
1082 void wlc_phy_mute_upd(struct brcms_phy_pub
*pih
, bool mute
, u32 flags
)
1084 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1087 mboolset(pi
->measure_hold
, PHY_HOLD_FOR_MUTE
);
1089 mboolclr(pi
->measure_hold
, PHY_HOLD_FOR_MUTE
);
1091 if (!mute
&& (flags
& PHY_MUTE_FOR_PREISM
))
1092 pi
->nphy_perical_last
= pi
->sh
->now
- pi
->sh
->glacial_timer
;
1096 void wlc_phy_clear_tssi(struct brcms_phy_pub
*pih
)
1098 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1103 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_B_TSSI_0
, NULL_TSSI_W
);
1104 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_B_TSSI_1
, NULL_TSSI_W
);
1105 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_G_TSSI_0
, NULL_TSSI_W
);
1106 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_G_TSSI_1
, NULL_TSSI_W
);
1110 static bool wlc_phy_cal_txpower_recalc_sw(struct brcms_phy
*pi
)
1115 void wlc_phy_switch_radio(struct brcms_phy_pub
*pih
, bool on
)
1117 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1118 (void)bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
1121 wlc_phy_switch_radio_nphy(pi
, on
);
1122 } else if (ISLCNPHY(pi
)) {
1124 and_phy_reg(pi
, 0x44c,
1127 (0x1 << 10) | (0x1 << 11) | (0x1 << 12)));
1128 and_phy_reg(pi
, 0x4b0, ~((0x1 << 3) | (0x1 << 11)));
1129 and_phy_reg(pi
, 0x4f9, ~(0x1 << 3));
1131 and_phy_reg(pi
, 0x44d,
1134 (0x1 << 12) | (0x1 << 13) | (0x1 << 14)));
1135 or_phy_reg(pi
, 0x44c,
1138 (0x1 << 10) | (0x1 << 11) | (0x1 << 12));
1140 and_phy_reg(pi
, 0x4b7, ~((0x7f << 8)));
1141 and_phy_reg(pi
, 0x4b1, ~((0x1 << 13)));
1142 or_phy_reg(pi
, 0x4b0, (0x1 << 3) | (0x1 << 11));
1143 and_phy_reg(pi
, 0x4fa, ~((0x1 << 3)));
1144 or_phy_reg(pi
, 0x4f9, (0x1 << 3));
1149 u16
wlc_phy_bw_state_get(struct brcms_phy_pub
*ppi
)
1151 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1156 void wlc_phy_bw_state_set(struct brcms_phy_pub
*ppi
, u16 bw
)
1158 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1163 void wlc_phy_chanspec_radio_set(struct brcms_phy_pub
*ppi
, u16 newch
)
1165 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1166 pi
->radio_chanspec
= newch
;
1170 u16
wlc_phy_chanspec_get(struct brcms_phy_pub
*ppi
)
1172 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1174 return pi
->radio_chanspec
;
1177 void wlc_phy_chanspec_set(struct brcms_phy_pub
*ppi
, u16 chanspec
)
1179 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1181 void (*chanspec_set
)(struct brcms_phy
*, u16
) = NULL
;
1182 m_cur_channel
= CHSPEC_CHANNEL(chanspec
);
1183 if (CHSPEC_IS5G(chanspec
))
1184 m_cur_channel
|= D11_CURCHANNEL_5G
;
1185 if (CHSPEC_IS40(chanspec
))
1186 m_cur_channel
|= D11_CURCHANNEL_40
;
1187 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_CURCHANNEL
, m_cur_channel
);
1189 chanspec_set
= pi
->pi_fptr
.chanset
;
1191 (*chanspec_set
)(pi
, chanspec
);
1195 int wlc_phy_chanspec_freq2bandrange_lpssn(uint freq
)
1200 range
= WL_CHAN_FREQ_RANGE_2G
;
1201 else if (freq
<= 5320)
1202 range
= WL_CHAN_FREQ_RANGE_5GL
;
1203 else if (freq
<= 5700)
1204 range
= WL_CHAN_FREQ_RANGE_5GM
;
1206 range
= WL_CHAN_FREQ_RANGE_5GH
;
1211 int wlc_phy_chanspec_bandrange_get(struct brcms_phy
*pi
, u16 chanspec
)
1214 uint channel
= CHSPEC_CHANNEL(chanspec
);
1215 uint freq
= wlc_phy_channel2freq(channel
);
1218 range
= wlc_phy_get_chan_freq_range_nphy(pi
, channel
);
1219 else if (ISLCNPHY(pi
))
1220 range
= wlc_phy_chanspec_freq2bandrange_lpssn(freq
);
1225 void wlc_phy_chanspec_ch14_widefilter_set(struct brcms_phy_pub
*ppi
,
1228 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1230 pi
->channel_14_wide_filter
= wide_filter
;
1234 int wlc_phy_channel2freq(uint channel
)
1238 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++)
1239 if (chan_info_all
[i
].chan
== channel
)
1240 return chan_info_all
[i
].freq
;
1245 wlc_phy_chanspec_band_validch(struct brcms_phy_pub
*ppi
, uint band
,
1246 struct brcms_chanvec
*channels
)
1248 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1252 memset(channels
, 0, sizeof(struct brcms_chanvec
));
1254 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1255 channel
= chan_info_all
[i
].chan
;
1257 if ((pi
->a_band_high_disable
) && (channel
>= FIRST_REF5_CHANNUM
)
1258 && (channel
<= LAST_REF5_CHANNUM
))
1261 if ((band
== BRCM_BAND_2G
&& channel
<= CH_MAX_2G_CHANNEL
) ||
1262 (band
== BRCM_BAND_5G
&& channel
> CH_MAX_2G_CHANNEL
))
1263 setbit(channels
->vec
, channel
);
1267 u16
wlc_phy_chanspec_band_firstch(struct brcms_phy_pub
*ppi
, uint band
)
1269 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1274 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1275 channel
= chan_info_all
[i
].chan
;
1277 if (ISNPHY(pi
) && pi
->bw
== WL_CHANSPEC_BW_40
) {
1280 for (j
= 0; j
< ARRAY_SIZE(chan_info_all
); j
++) {
1281 if (chan_info_all
[j
].chan
==
1282 channel
+ CH_10MHZ_APART
)
1286 if (j
== ARRAY_SIZE(chan_info_all
))
1289 channel
= upper_20_sb(channel
);
1290 chspec
= channel
| WL_CHANSPEC_BW_40
|
1291 WL_CHANSPEC_CTL_SB_LOWER
;
1292 if (band
== BRCM_BAND_2G
)
1293 chspec
|= WL_CHANSPEC_BAND_2G
;
1295 chspec
|= WL_CHANSPEC_BAND_5G
;
1297 chspec
= ch20mhz_chspec(channel
);
1299 if ((pi
->a_band_high_disable
) && (channel
>= FIRST_REF5_CHANNUM
)
1300 && (channel
<= LAST_REF5_CHANNUM
))
1303 if ((band
== BRCM_BAND_2G
&& channel
<= CH_MAX_2G_CHANNEL
) ||
1304 (band
== BRCM_BAND_5G
&& channel
> CH_MAX_2G_CHANNEL
))
1308 return (u16
) INVCHANSPEC
;
1311 int wlc_phy_txpower_get(struct brcms_phy_pub
*ppi
, uint
*qdbm
, bool *override
)
1313 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1315 *qdbm
= pi
->tx_user_target
[0];
1316 if (override
!= NULL
)
1317 *override
= pi
->txpwroverride
;
1321 void wlc_phy_txpower_target_set(struct brcms_phy_pub
*ppi
,
1322 struct txpwr_limits
*txpwr
)
1324 bool mac_enabled
= false;
1325 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1327 memcpy(&pi
->tx_user_target
[TXP_FIRST_CCK
],
1328 &txpwr
->cck
[0], BRCMS_NUM_RATES_CCK
);
1330 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM
],
1331 &txpwr
->ofdm
[0], BRCMS_NUM_RATES_OFDM
);
1332 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_20_CDD
],
1333 &txpwr
->ofdm_cdd
[0], BRCMS_NUM_RATES_OFDM
);
1335 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_40_SISO
],
1336 &txpwr
->ofdm_40_siso
[0], BRCMS_NUM_RATES_OFDM
);
1337 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_40_CDD
],
1338 &txpwr
->ofdm_40_cdd
[0], BRCMS_NUM_RATES_OFDM
);
1340 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_SISO
],
1341 &txpwr
->mcs_20_siso
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1342 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_CDD
],
1343 &txpwr
->mcs_20_cdd
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1344 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_STBC
],
1345 &txpwr
->mcs_20_stbc
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1346 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_SDM
],
1347 &txpwr
->mcs_20_mimo
[0], BRCMS_NUM_RATES_MCS_2_STREAM
);
1349 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_SISO
],
1350 &txpwr
->mcs_40_siso
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1351 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_CDD
],
1352 &txpwr
->mcs_40_cdd
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1353 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_STBC
],
1354 &txpwr
->mcs_40_stbc
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1355 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_SDM
],
1356 &txpwr
->mcs_40_mimo
[0], BRCMS_NUM_RATES_MCS_2_STREAM
);
1358 if (bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) & MCTL_EN_MAC
)
1362 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1364 wlc_phy_txpower_recalc_target(pi
);
1365 wlc_phy_cal_txpower_recalc_sw(pi
);
1368 wlapi_enable_mac(pi
->sh
->physhim
);
1371 int wlc_phy_txpower_set(struct brcms_phy_pub
*ppi
, uint qdbm
, bool override
)
1373 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1379 for (i
= 0; i
< TXP_NUM_RATES
; i
++)
1380 pi
->tx_user_target
[i
] = (u8
) qdbm
;
1382 pi
->txpwroverride
= false;
1385 if (!SCAN_INPROG_PHY(pi
)) {
1388 suspend
= (0 == (bcma_read32(pi
->d11core
,
1389 D11REGOFFS(maccontrol
)) &
1393 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1395 wlc_phy_txpower_recalc_target(pi
);
1396 wlc_phy_cal_txpower_recalc_sw(pi
);
1399 wlapi_enable_mac(pi
->sh
->physhim
);
1406 wlc_phy_txpower_sromlimit(struct brcms_phy_pub
*ppi
, uint channel
, u8
*min_pwr
,
1407 u8
*max_pwr
, int txp_rate_idx
)
1409 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1412 *min_pwr
= pi
->min_txpower
* BRCMS_TXPWR_DB_FACTOR
;
1415 if (txp_rate_idx
< 0)
1416 txp_rate_idx
= TXP_FIRST_CCK
;
1417 wlc_phy_txpower_sromlimit_get_nphy(pi
, channel
, max_pwr
,
1420 } else if ((channel
<= CH_MAX_2G_CHANNEL
)) {
1421 if (txp_rate_idx
< 0)
1422 txp_rate_idx
= TXP_FIRST_CCK
;
1423 *max_pwr
= pi
->tx_srom_max_rate_2g
[txp_rate_idx
];
1426 *max_pwr
= BRCMS_TXPWR_MAX
;
1428 if (txp_rate_idx
< 0)
1429 txp_rate_idx
= TXP_FIRST_OFDM
;
1431 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1432 if (channel
== chan_info_all
[i
].chan
)
1437 *max_pwr
= pi
->hwtxpwr
[i
];
1440 if ((i
>= FIRST_MID_5G_CHAN
) && (i
<= LAST_MID_5G_CHAN
))
1442 pi
->tx_srom_max_rate_5g_mid
[txp_rate_idx
];
1443 if ((i
>= FIRST_HIGH_5G_CHAN
)
1444 && (i
<= LAST_HIGH_5G_CHAN
))
1446 pi
->tx_srom_max_rate_5g_hi
[txp_rate_idx
];
1447 if ((i
>= FIRST_LOW_5G_CHAN
) && (i
<= LAST_LOW_5G_CHAN
))
1449 pi
->tx_srom_max_rate_5g_low
[txp_rate_idx
];
1455 wlc_phy_txpower_sromlimit_max_get(struct brcms_phy_pub
*ppi
, uint chan
,
1456 u8
*max_txpwr
, u8
*min_txpwr
)
1458 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1460 u8 tx_pwr_min
= 255;
1462 u8 maxtxpwr
, mintxpwr
, rate
, pactrl
;
1466 max_num_rate
= ISNPHY(pi
) ? TXP_NUM_RATES
:
1467 ISLCNPHY(pi
) ? (TXP_LAST_SISO_MCS_20
+
1468 1) : (TXP_LAST_OFDM
+ 1);
1470 for (rate
= 0; rate
< max_num_rate
; rate
++) {
1472 wlc_phy_txpower_sromlimit(ppi
, chan
, &mintxpwr
, &maxtxpwr
,
1475 maxtxpwr
= (maxtxpwr
> pactrl
) ? (maxtxpwr
- pactrl
) : 0;
1477 maxtxpwr
= (maxtxpwr
> 6) ? (maxtxpwr
- 6) : 0;
1479 tx_pwr_max
= max(tx_pwr_max
, maxtxpwr
);
1480 tx_pwr_min
= min(tx_pwr_min
, maxtxpwr
);
1482 *max_txpwr
= tx_pwr_max
;
1483 *min_txpwr
= tx_pwr_min
;
1487 wlc_phy_txpower_boardlimit_band(struct brcms_phy_pub
*ppi
, uint bandunit
,
1488 s32
*max_pwr
, s32
*min_pwr
, u32
*step_pwr
)
1493 u8
wlc_phy_txpower_get_target_min(struct brcms_phy_pub
*ppi
)
1495 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1497 return pi
->tx_power_min
;
1500 u8
wlc_phy_txpower_get_target_max(struct brcms_phy_pub
*ppi
)
1502 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1504 return pi
->tx_power_max
;
1507 static s8
wlc_phy_env_measure_vbat(struct brcms_phy
*pi
)
1510 return wlc_lcnphy_vbatsense(pi
, 0);
1515 static s8
wlc_phy_env_measure_temperature(struct brcms_phy
*pi
)
1518 return wlc_lcnphy_tempsense_degree(pi
, 0);
1523 static void wlc_phy_upd_env_txpwr_rate_limits(struct brcms_phy
*pi
, u32 band
)
1528 for (i
= 0; i
< TXP_NUM_RATES
; i
++)
1529 pi
->txpwr_env_limit
[i
] = BRCMS_TXPWR_MAX
;
1531 vbat
= wlc_phy_env_measure_vbat(pi
);
1532 temp
= wlc_phy_env_measure_temperature(pi
);
1537 wlc_user_txpwr_antport_to_rfport(struct brcms_phy
*pi
, uint chan
, u32 band
,
1542 if (!pi
->user_txpwr_at_rfport
)
1547 void wlc_phy_txpower_recalc_target(struct brcms_phy
*pi
)
1549 u8 maxtxpwr
, mintxpwr
, rate
, pactrl
;
1551 u8 tx_pwr_target
[TXP_NUM_RATES
];
1553 u8 tx_pwr_min
= 255;
1554 u8 tx_pwr_max_rate_ind
= 0;
1558 u32 band
= CHSPEC2BAND(pi
->radio_chanspec
);
1559 void (*txpwr_recalc_fn
)(struct brcms_phy
*) = NULL
;
1561 chspec
= pi
->radio_chanspec
;
1562 if (CHSPEC_CTL_SB(chspec
) == WL_CHANSPEC_CTL_SB_NONE
)
1563 target_chan
= CHSPEC_CHANNEL(chspec
);
1564 else if (CHSPEC_CTL_SB(chspec
) == WL_CHANSPEC_CTL_SB_UPPER
)
1565 target_chan
= upper_20_sb(CHSPEC_CHANNEL(chspec
));
1567 target_chan
= lower_20_sb(CHSPEC_CHANNEL(chspec
));
1573 if (CHSPEC_IS40(pi
->radio_chanspec
)) {
1574 offset_mcs
= pi
->mcs40_po
;
1575 for (i
= TXP_FIRST_SISO_MCS_20
;
1576 i
<= TXP_LAST_SISO_MCS_20
; i
++) {
1577 pi
->tx_srom_max_rate_2g
[i
- 8] =
1578 pi
->tx_srom_max_2g
-
1579 ((offset_mcs
& 0xf) * 2);
1583 offset_mcs
= pi
->mcs20_po
;
1584 for (i
= TXP_FIRST_SISO_MCS_20
;
1585 i
<= TXP_LAST_SISO_MCS_20
; i
++) {
1586 pi
->tx_srom_max_rate_2g
[i
- 8] =
1587 pi
->tx_srom_max_2g
-
1588 ((offset_mcs
& 0xf) * 2);
1594 max_num_rate
= ((ISNPHY(pi
)) ? (TXP_NUM_RATES
) :
1596 (TXP_LAST_SISO_MCS_20
+ 1) : (TXP_LAST_OFDM
+ 1)));
1598 wlc_phy_upd_env_txpwr_rate_limits(pi
, band
);
1600 for (rate
= start_rate
; rate
< max_num_rate
; rate
++) {
1602 tx_pwr_target
[rate
] = pi
->tx_user_target
[rate
];
1604 if (pi
->user_txpwr_at_rfport
)
1605 tx_pwr_target
[rate
] +=
1606 wlc_user_txpwr_antport_to_rfport(pi
,
1611 wlc_phy_txpower_sromlimit((struct brcms_phy_pub
*) pi
,
1613 &mintxpwr
, &maxtxpwr
, rate
);
1615 maxtxpwr
= min(maxtxpwr
, pi
->txpwr_limit
[rate
]);
1617 maxtxpwr
= (maxtxpwr
> pactrl
) ? (maxtxpwr
- pactrl
) : 0;
1619 maxtxpwr
= (maxtxpwr
> 6) ? (maxtxpwr
- 6) : 0;
1621 maxtxpwr
= min(maxtxpwr
, tx_pwr_target
[rate
]);
1623 if (pi
->txpwr_percent
<= 100)
1624 maxtxpwr
= (maxtxpwr
* pi
->txpwr_percent
) / 100;
1626 tx_pwr_target
[rate
] = max(maxtxpwr
, mintxpwr
);
1628 tx_pwr_target
[rate
] =
1629 min(tx_pwr_target
[rate
], pi
->txpwr_env_limit
[rate
]);
1631 if (tx_pwr_target
[rate
] > tx_pwr_max
)
1632 tx_pwr_max_rate_ind
= rate
;
1634 tx_pwr_max
= max(tx_pwr_max
, tx_pwr_target
[rate
]);
1635 tx_pwr_min
= min(tx_pwr_min
, tx_pwr_target
[rate
]);
1638 memset(pi
->tx_power_offset
, 0, sizeof(pi
->tx_power_offset
));
1639 pi
->tx_power_max
= tx_pwr_max
;
1640 pi
->tx_power_min
= tx_pwr_min
;
1641 pi
->tx_power_max_rate_ind
= tx_pwr_max_rate_ind
;
1642 for (rate
= 0; rate
< max_num_rate
; rate
++) {
1644 pi
->tx_power_target
[rate
] = tx_pwr_target
[rate
];
1646 if (!pi
->hwpwrctrl
|| ISNPHY(pi
))
1647 pi
->tx_power_offset
[rate
] =
1648 pi
->tx_power_max
- pi
->tx_power_target
[rate
];
1650 pi
->tx_power_offset
[rate
] =
1651 pi
->tx_power_target
[rate
] - pi
->tx_power_min
;
1654 txpwr_recalc_fn
= pi
->pi_fptr
.txpwrrecalc
;
1655 if (txpwr_recalc_fn
)
1656 (*txpwr_recalc_fn
)(pi
);
1660 wlc_phy_txpower_reg_limit_calc(struct brcms_phy
*pi
, struct txpwr_limits
*txpwr
,
1663 u8 tmp_txpwr_limit
[2 * BRCMS_NUM_RATES_OFDM
];
1664 u8
*txpwr_ptr1
= NULL
, *txpwr_ptr2
= NULL
;
1665 int rate_start_index
= 0, rate1
, rate2
, k
;
1667 for (rate1
= WL_TX_POWER_CCK_FIRST
, rate2
= 0;
1668 rate2
< WL_TX_POWER_CCK_NUM
; rate1
++, rate2
++)
1669 pi
->txpwr_limit
[rate1
] = txpwr
->cck
[rate2
];
1671 for (rate1
= WL_TX_POWER_OFDM_FIRST
, rate2
= 0;
1672 rate2
< WL_TX_POWER_OFDM_NUM
; rate1
++, rate2
++)
1673 pi
->txpwr_limit
[rate1
] = txpwr
->ofdm
[rate2
];
1677 for (k
= 0; k
< 4; k
++) {
1681 txpwr_ptr1
= txpwr
->mcs_20_siso
;
1682 txpwr_ptr2
= txpwr
->ofdm
;
1683 rate_start_index
= WL_TX_POWER_OFDM_FIRST
;
1687 txpwr_ptr1
= txpwr
->mcs_20_cdd
;
1688 txpwr_ptr2
= txpwr
->ofdm_cdd
;
1689 rate_start_index
= WL_TX_POWER_OFDM20_CDD_FIRST
;
1693 txpwr_ptr1
= txpwr
->mcs_40_siso
;
1694 txpwr_ptr2
= txpwr
->ofdm_40_siso
;
1696 WL_TX_POWER_OFDM40_SISO_FIRST
;
1700 txpwr_ptr1
= txpwr
->mcs_40_cdd
;
1701 txpwr_ptr2
= txpwr
->ofdm_40_cdd
;
1702 rate_start_index
= WL_TX_POWER_OFDM40_CDD_FIRST
;
1706 for (rate2
= 0; rate2
< BRCMS_NUM_RATES_OFDM
;
1708 tmp_txpwr_limit
[rate2
] = 0;
1709 tmp_txpwr_limit
[BRCMS_NUM_RATES_OFDM
+ rate2
] =
1712 wlc_phy_mcs_to_ofdm_powers_nphy(
1714 BRCMS_NUM_RATES_OFDM
-
1715 1, BRCMS_NUM_RATES_OFDM
);
1716 for (rate1
= rate_start_index
, rate2
= 0;
1717 rate2
< BRCMS_NUM_RATES_OFDM
; rate1
++, rate2
++)
1718 pi
->txpwr_limit
[rate1
] =
1719 min(txpwr_ptr2
[rate2
],
1720 tmp_txpwr_limit
[rate2
]);
1723 for (k
= 0; k
< 4; k
++) {
1727 txpwr_ptr1
= txpwr
->ofdm
;
1728 txpwr_ptr2
= txpwr
->mcs_20_siso
;
1729 rate_start_index
= WL_TX_POWER_MCS20_SISO_FIRST
;
1733 txpwr_ptr1
= txpwr
->ofdm_cdd
;
1734 txpwr_ptr2
= txpwr
->mcs_20_cdd
;
1735 rate_start_index
= WL_TX_POWER_MCS20_CDD_FIRST
;
1739 txpwr_ptr1
= txpwr
->ofdm_40_siso
;
1740 txpwr_ptr2
= txpwr
->mcs_40_siso
;
1741 rate_start_index
= WL_TX_POWER_MCS40_SISO_FIRST
;
1745 txpwr_ptr1
= txpwr
->ofdm_40_cdd
;
1746 txpwr_ptr2
= txpwr
->mcs_40_cdd
;
1747 rate_start_index
= WL_TX_POWER_MCS40_CDD_FIRST
;
1750 for (rate2
= 0; rate2
< BRCMS_NUM_RATES_OFDM
;
1752 tmp_txpwr_limit
[rate2
] = 0;
1753 tmp_txpwr_limit
[BRCMS_NUM_RATES_OFDM
+ rate2
] =
1756 wlc_phy_ofdm_to_mcs_powers_nphy(
1758 BRCMS_NUM_RATES_OFDM
-
1759 1, BRCMS_NUM_RATES_OFDM
);
1760 for (rate1
= rate_start_index
, rate2
= 0;
1761 rate2
< BRCMS_NUM_RATES_MCS_1_STREAM
;
1763 pi
->txpwr_limit
[rate1
] =
1764 min(txpwr_ptr2
[rate2
],
1765 tmp_txpwr_limit
[rate2
]);
1768 for (k
= 0; k
< 2; k
++) {
1772 rate_start_index
= WL_TX_POWER_MCS20_STBC_FIRST
;
1773 txpwr_ptr1
= txpwr
->mcs_20_stbc
;
1777 rate_start_index
= WL_TX_POWER_MCS40_STBC_FIRST
;
1778 txpwr_ptr1
= txpwr
->mcs_40_stbc
;
1781 for (rate1
= rate_start_index
, rate2
= 0;
1782 rate2
< BRCMS_NUM_RATES_MCS_1_STREAM
;
1784 pi
->txpwr_limit
[rate1
] = txpwr_ptr1
[rate2
];
1787 for (k
= 0; k
< 2; k
++) {
1791 rate_start_index
= WL_TX_POWER_MCS20_SDM_FIRST
;
1792 txpwr_ptr1
= txpwr
->mcs_20_mimo
;
1796 rate_start_index
= WL_TX_POWER_MCS40_SDM_FIRST
;
1797 txpwr_ptr1
= txpwr
->mcs_40_mimo
;
1800 for (rate1
= rate_start_index
, rate2
= 0;
1801 rate2
< BRCMS_NUM_RATES_MCS_2_STREAM
;
1803 pi
->txpwr_limit
[rate1
] = txpwr_ptr1
[rate2
];
1806 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
] = txpwr
->mcs32
;
1808 pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
] =
1809 min(pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
],
1810 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
]);
1811 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
] =
1812 pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
];
1816 void wlc_phy_txpwr_percent_set(struct brcms_phy_pub
*ppi
, u8 txpwr_percent
)
1818 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1820 pi
->txpwr_percent
= txpwr_percent
;
1823 void wlc_phy_machwcap_set(struct brcms_phy_pub
*ppi
, u32 machwcap
)
1825 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1827 pi
->sh
->machwcap
= machwcap
;
1830 void wlc_phy_runbist_config(struct brcms_phy_pub
*ppi
, bool start_end
)
1832 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1836 if (start_end
== ON
) {
1840 if (NREV_IS(pi
->pubpi
.phy_rev
, 3)
1841 || NREV_IS(pi
->pubpi
.phy_rev
, 4)) {
1842 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
),
1844 bcma_set16(pi
->d11core
, D11REGOFFS(phyregdata
),
1848 if (NREV_IS(pi
->pubpi
.phy_rev
, 3)
1849 || NREV_IS(pi
->pubpi
.phy_rev
, 4)) {
1850 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
),
1852 bcma_write16(pi
->d11core
, D11REGOFFS(phyregdata
), rxc
);
1855 wlc_phy_por_inform(ppi
);
1860 wlc_phy_txpower_limit_set(struct brcms_phy_pub
*ppi
, struct txpwr_limits
*txpwr
,
1863 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1865 wlc_phy_txpower_reg_limit_calc(pi
, txpwr
, chanspec
);
1869 for (i
= TXP_FIRST_OFDM_20_CDD
, j
= 0;
1870 j
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++, j
++) {
1871 if (txpwr
->mcs_20_siso
[j
])
1872 pi
->txpwr_limit
[i
] = txpwr
->mcs_20_siso
[j
];
1874 pi
->txpwr_limit
[i
] = txpwr
->ofdm
[j
];
1878 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1880 wlc_phy_txpower_recalc_target(pi
);
1881 wlc_phy_cal_txpower_recalc_sw(pi
);
1882 wlapi_enable_mac(pi
->sh
->physhim
);
1885 void wlc_phy_ofdm_rateset_war(struct brcms_phy_pub
*pih
, bool war
)
1887 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1889 pi
->ofdm_rateset_war
= war
;
1892 void wlc_phy_bf_preempt_enable(struct brcms_phy_pub
*pih
, bool bf_preempt
)
1894 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1896 pi
->bf_preempt_4306
= bf_preempt
;
1899 void wlc_phy_txpower_update_shm(struct brcms_phy
*pi
)
1908 if (pi
->hwpwrctrl
) {
1911 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_MAX
, 63);
1912 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_N
,
1913 1 << NUM_TSSI_FRAMES
);
1915 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_TARGET
,
1916 pi
->tx_power_min
<< NUM_TSSI_FRAMES
);
1918 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_CUR
,
1921 for (j
= TXP_FIRST_OFDM
; j
<= TXP_LAST_OFDM
; j
++) {
1922 const u8 ucode_ofdm_rates
[] = {
1923 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c
1925 offset
= wlapi_bmac_rate_shm_offset(
1927 ucode_ofdm_rates
[j
- TXP_FIRST_OFDM
]);
1928 wlapi_bmac_write_shm(pi
->sh
->physhim
, offset
+ 6,
1929 pi
->tx_power_offset
[j
]);
1930 wlapi_bmac_write_shm(pi
->sh
->physhim
, offset
+ 14,
1931 -(pi
->tx_power_offset
[j
] / 2));
1934 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF2
, MHF2_HWPWRCTL
,
1935 MHF2_HWPWRCTL
, BRCM_BAND_ALL
);
1939 for (i
= TXP_FIRST_OFDM
; i
<= TXP_LAST_OFDM
; i
++)
1940 pi
->tx_power_offset
[i
] =
1941 (u8
) roundup(pi
->tx_power_offset
[i
], 8);
1942 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_OFDM_OFFSET
,
1944 ((pi
->tx_power_offset
[TXP_FIRST_OFDM
]
1949 bool wlc_phy_txpower_hw_ctrl_get(struct brcms_phy_pub
*ppi
)
1951 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1954 return pi
->nphy_txpwrctrl
;
1956 return pi
->hwpwrctrl
;
1959 void wlc_phy_txpower_hw_ctrl_set(struct brcms_phy_pub
*ppi
, bool hwpwrctrl
)
1961 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1964 if (!pi
->hwpwrctrl_capable
)
1967 pi
->hwpwrctrl
= hwpwrctrl
;
1968 pi
->nphy_txpwrctrl
= hwpwrctrl
;
1969 pi
->txpwrctrl
= hwpwrctrl
;
1972 suspend
= (0 == (bcma_read32(pi
->d11core
,
1973 D11REGOFFS(maccontrol
)) &
1976 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1978 wlc_phy_txpwrctrl_enable_nphy(pi
, pi
->nphy_txpwrctrl
);
1979 if (pi
->nphy_txpwrctrl
== PHY_TPC_HW_OFF
)
1980 wlc_phy_txpwr_fixpower_nphy(pi
);
1982 mod_phy_reg(pi
, 0x1e7, (0x7f << 0),
1983 pi
->saved_txpwr_idx
);
1986 wlapi_enable_mac(pi
->sh
->physhim
);
1990 void wlc_phy_txpower_ipa_upd(struct brcms_phy
*pi
)
1993 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
1994 pi
->ipa2g_on
= (pi
->srom_fem2g
.extpagain
== 2);
1995 pi
->ipa5g_on
= (pi
->srom_fem5g
.extpagain
== 2);
1997 pi
->ipa2g_on
= false;
1998 pi
->ipa5g_on
= false;
2002 static u32
wlc_phy_txpower_est_power_nphy(struct brcms_phy
*pi
)
2004 s16 tx0_status
, tx1_status
;
2005 u16 estPower1
, estPower2
;
2006 u8 pwr0
, pwr1
, adj_pwr0
, adj_pwr1
;
2009 estPower1
= read_phy_reg(pi
, 0x118);
2010 estPower2
= read_phy_reg(pi
, 0x119);
2012 if ((estPower1
& (0x1 << 8)) == (0x1 << 8))
2013 pwr0
= (u8
) (estPower1
& (0xff << 0)) >> 0;
2017 if ((estPower2
& (0x1 << 8)) == (0x1 << 8))
2018 pwr1
= (u8
) (estPower2
& (0xff << 0)) >> 0;
2022 tx0_status
= read_phy_reg(pi
, 0x1ed);
2023 tx1_status
= read_phy_reg(pi
, 0x1ee);
2025 if ((tx0_status
& (0x1 << 15)) == (0x1 << 15))
2026 adj_pwr0
= (u8
) (tx0_status
& (0xff << 0)) >> 0;
2029 if ((tx1_status
& (0x1 << 15)) == (0x1 << 15))
2030 adj_pwr1
= (u8
) (tx1_status
& (0xff << 0)) >> 0;
2034 est_pwr
= (u32
) ((pwr0
<< 24) | (pwr1
<< 16) | (adj_pwr0
<< 8) |
2041 wlc_phy_txpower_get_current(struct brcms_phy_pub
*ppi
, struct tx_power
*power
,
2044 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2045 uint rate
, num_rates
;
2046 u8 min_pwr
, max_pwr
;
2048 #if WL_TX_POWER_RATES != TXP_NUM_RATES
2049 #error "struct tx_power out of sync with this fn"
2053 power
->rf_cores
= 2;
2054 power
->flags
|= (WL_TX_POWER_F_MIMO
);
2055 if (pi
->nphy_txpwrctrl
== PHY_TPC_HW_ON
)
2057 (WL_TX_POWER_F_ENABLED
| WL_TX_POWER_F_HW
);
2058 } else if (ISLCNPHY(pi
)) {
2059 power
->rf_cores
= 1;
2060 power
->flags
|= (WL_TX_POWER_F_SISO
);
2061 if (pi
->radiopwr_override
== RADIOPWR_OVERRIDE_DEF
)
2062 power
->flags
|= WL_TX_POWER_F_ENABLED
;
2064 power
->flags
|= WL_TX_POWER_F_HW
;
2067 num_rates
= ((ISNPHY(pi
)) ? (TXP_NUM_RATES
) :
2069 (TXP_LAST_OFDM_20_CDD
+ 1) : (TXP_LAST_OFDM
+ 1)));
2071 for (rate
= 0; rate
< num_rates
; rate
++) {
2072 power
->user_limit
[rate
] = pi
->tx_user_target
[rate
];
2073 wlc_phy_txpower_sromlimit(ppi
, channel
, &min_pwr
, &max_pwr
,
2075 power
->board_limit
[rate
] = (u8
) max_pwr
;
2076 power
->target
[rate
] = pi
->tx_power_target
[rate
];
2082 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2083 wlc_phyreg_enter((struct brcms_phy_pub
*) pi
);
2084 est_pout
= wlc_phy_txpower_est_power_nphy(pi
);
2085 wlc_phyreg_exit((struct brcms_phy_pub
*) pi
);
2086 wlapi_enable_mac(pi
->sh
->physhim
);
2088 power
->est_Pout
[0] = (est_pout
>> 8) & 0xff;
2089 power
->est_Pout
[1] = est_pout
& 0xff;
2091 power
->est_Pout_act
[0] = est_pout
>> 24;
2092 power
->est_Pout_act
[1] = (est_pout
>> 16) & 0xff;
2094 if (power
->est_Pout
[0] == 0x80)
2095 power
->est_Pout
[0] = 0;
2096 if (power
->est_Pout
[1] == 0x80)
2097 power
->est_Pout
[1] = 0;
2099 if (power
->est_Pout_act
[0] == 0x80)
2100 power
->est_Pout_act
[0] = 0;
2101 if (power
->est_Pout_act
[1] == 0x80)
2102 power
->est_Pout_act
[1] = 0;
2104 power
->est_Pout_cck
= 0;
2106 power
->tx_power_max
[0] = pi
->tx_power_max
;
2107 power
->tx_power_max
[1] = pi
->tx_power_max
;
2109 power
->tx_power_max_rate_ind
[0] = pi
->tx_power_max_rate_ind
;
2110 power
->tx_power_max_rate_ind
[1] = pi
->tx_power_max_rate_ind
;
2111 } else if (pi
->hwpwrctrl
&& pi
->sh
->up
) {
2113 wlc_phyreg_enter(ppi
);
2116 power
->tx_power_max
[0] = pi
->tx_power_max
;
2117 power
->tx_power_max
[1] = pi
->tx_power_max
;
2119 power
->tx_power_max_rate_ind
[0] =
2120 pi
->tx_power_max_rate_ind
;
2121 power
->tx_power_max_rate_ind
[1] =
2122 pi
->tx_power_max_rate_ind
;
2124 if (wlc_phy_tpc_isenabled_lcnphy(pi
))
2127 WL_TX_POWER_F_ENABLED
);
2130 ~(WL_TX_POWER_F_HW
|
2131 WL_TX_POWER_F_ENABLED
);
2133 wlc_lcnphy_get_tssi(pi
, (s8
*) &power
->est_Pout
[0],
2134 (s8
*) &power
->est_Pout_cck
);
2136 wlc_phyreg_exit(ppi
);
2140 void wlc_phy_antsel_type_set(struct brcms_phy_pub
*ppi
, u8 antsel_type
)
2142 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2144 pi
->antsel_type
= antsel_type
;
2147 bool wlc_phy_test_ison(struct brcms_phy_pub
*ppi
)
2149 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2151 return pi
->phytest_on
;
2154 void wlc_phy_ant_rxdiv_set(struct brcms_phy_pub
*ppi
, u8 val
)
2156 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2159 pi
->sh
->rx_antdiv
= val
;
2161 if (!(ISNPHY(pi
) && D11REV_IS(pi
->sh
->corerev
, 16))) {
2162 if (val
> ANT_RX_DIV_FORCE_1
)
2163 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF1
, MHF1_ANTDIV
,
2164 MHF1_ANTDIV
, BRCM_BAND_ALL
);
2166 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF1
, MHF1_ANTDIV
, 0,
2176 suspend
= (0 == (bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) &
2179 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2182 if (val
> ANT_RX_DIV_FORCE_1
) {
2183 mod_phy_reg(pi
, 0x410, (0x1 << 1), 0x01 << 1);
2184 mod_phy_reg(pi
, 0x410,
2186 ((ANT_RX_DIV_START_1
== val
) ? 1 : 0) << 0);
2188 mod_phy_reg(pi
, 0x410, (0x1 << 1), 0x00 << 1);
2189 mod_phy_reg(pi
, 0x410, (0x1 << 0), (u16
) val
<< 0);
2194 wlapi_enable_mac(pi
->sh
->physhim
);
2200 wlc_phy_noise_calc_phy(struct brcms_phy
*pi
, u32
*cmplx_pwr
, s8
*pwr_ant
)
2202 s8 cmplx_pwr_dbm
[PHY_CORE_MAX
];
2205 memset((u8
*) cmplx_pwr_dbm
, 0, sizeof(cmplx_pwr_dbm
));
2206 wlc_phy_compute_dB(cmplx_pwr
, cmplx_pwr_dbm
, pi
->pubpi
.phy_corenum
);
2208 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2209 if (NREV_GE(pi
->pubpi
.phy_rev
, 3))
2210 cmplx_pwr_dbm
[i
] += (s8
) PHY_NOISE_OFFSETFACT_4322
;
2213 cmplx_pwr_dbm
[i
] += (s8
) (16 - (15) * 3 - 70);
2216 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2217 pi
->nphy_noise_win
[i
][pi
->nphy_noise_index
] = cmplx_pwr_dbm
[i
];
2218 pwr_ant
[i
] = cmplx_pwr_dbm
[i
];
2220 pi
->nphy_noise_index
=
2221 MODINC_POW2(pi
->nphy_noise_index
, PHY_NOISE_WINDOW_SZ
);
2225 static void wlc_phy_noise_cb(struct brcms_phy
*pi
, u8 channel
, s8 noise_dbm
)
2227 if (!pi
->phynoise_state
)
2230 if (pi
->phynoise_state
& PHY_NOISE_STATE_MON
) {
2231 if (pi
->phynoise_chan_watchdog
== channel
) {
2232 pi
->sh
->phy_noise_window
[pi
->sh
->phy_noise_index
] =
2234 pi
->sh
->phy_noise_index
=
2235 MODINC(pi
->sh
->phy_noise_index
, MA_WINDOW_SZ
);
2237 pi
->phynoise_state
&= ~PHY_NOISE_STATE_MON
;
2240 if (pi
->phynoise_state
& PHY_NOISE_STATE_EXTERNAL
)
2241 pi
->phynoise_state
&= ~PHY_NOISE_STATE_EXTERNAL
;
2245 static s8
wlc_phy_noise_read_shmem(struct brcms_phy
*pi
)
2247 u32 cmplx_pwr
[PHY_CORE_MAX
];
2248 s8 noise_dbm_ant
[PHY_CORE_MAX
];
2250 u32 cmplx_pwr_tot
= 0;
2251 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2254 memset((u8
*) cmplx_pwr
, 0, sizeof(cmplx_pwr
));
2255 memset((u8
*) noise_dbm_ant
, 0, sizeof(noise_dbm_ant
));
2257 for (idx
= 0, core
= 0; core
< pi
->pubpi
.phy_corenum
; idx
+= 2,
2259 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP(idx
));
2260 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
,
2261 M_PWRIND_MAP(idx
+ 1));
2262 cmplx_pwr
[core
] = (hi
<< 16) + lo
;
2263 cmplx_pwr_tot
+= cmplx_pwr
[core
];
2264 if (cmplx_pwr
[core
] == 0)
2265 noise_dbm_ant
[core
] = PHY_NOISE_FIXED_VAL_NPHY
;
2267 cmplx_pwr
[core
] >>= PHY_NOISE_SAMPLE_LOG_NUM_UCODE
;
2270 if (cmplx_pwr_tot
!= 0)
2271 wlc_phy_noise_calc_phy(pi
, cmplx_pwr
, noise_dbm_ant
);
2273 for (core
= 0; core
< pi
->pubpi
.phy_corenum
; core
++) {
2274 pi
->nphy_noise_win
[core
][pi
->nphy_noise_index
] =
2275 noise_dbm_ant
[core
];
2277 if (noise_dbm_ant
[core
] > noise_dbm
)
2278 noise_dbm
= noise_dbm_ant
[core
];
2280 pi
->nphy_noise_index
=
2281 MODINC_POW2(pi
->nphy_noise_index
, PHY_NOISE_WINDOW_SZ
);
2287 void wlc_phy_noise_sample_intr(struct brcms_phy_pub
*pih
)
2289 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2292 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2295 u32 cmplx_pwr
, cmplx_pwr0
, cmplx_pwr1
;
2297 s32 pwr_offset_dB
, gain_dB
;
2298 u16 status_0
, status_1
;
2300 jssi_aux
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_AUX
);
2301 channel
= jssi_aux
& D11_CURCHANNEL_MAX
;
2303 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
);
2304 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
);
2305 cmplx_pwr0
= (hi
<< 16) + lo
;
2307 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
);
2308 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
);
2309 cmplx_pwr1
= (hi
<< 16) + lo
;
2310 cmplx_pwr
= (cmplx_pwr0
+ cmplx_pwr1
) >> 6;
2313 status_1
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_0
);
2314 if ((cmplx_pwr
> 0 && cmplx_pwr
< 500)
2315 && ((status_1
& 0xc000) == 0x4000)) {
2317 wlc_phy_compute_dB(&cmplx_pwr
, &noise_dbm
,
2318 pi
->pubpi
.phy_corenum
);
2319 pwr_offset_dB
= (read_phy_reg(pi
, 0x434) & 0xFF);
2320 if (pwr_offset_dB
> 127)
2321 pwr_offset_dB
-= 256;
2323 noise_dbm
+= (s8
) (pwr_offset_dB
- 30);
2325 gain_dB
= (status_0
& 0x1ff);
2326 noise_dbm
-= (s8
) (gain_dB
);
2328 noise_dbm
= PHY_NOISE_FIXED_VAL_LCNPHY
;
2330 } else if (ISNPHY(pi
)) {
2332 jssi_aux
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_AUX
);
2333 channel
= jssi_aux
& D11_CURCHANNEL_MAX
;
2335 noise_dbm
= wlc_phy_noise_read_shmem(pi
);
2338 wlc_phy_noise_cb(pi
, channel
, noise_dbm
);
2343 wlc_phy_noise_sample_request(struct brcms_phy_pub
*pih
, u8 reason
, u8 ch
)
2345 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2346 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2347 bool sampling_in_progress
= (pi
->phynoise_state
!= 0);
2348 bool wait_for_intr
= true;
2351 case PHY_NOISE_SAMPLE_MON
:
2352 pi
->phynoise_chan_watchdog
= ch
;
2353 pi
->phynoise_state
|= PHY_NOISE_STATE_MON
;
2356 case PHY_NOISE_SAMPLE_EXTERNAL
:
2357 pi
->phynoise_state
|= PHY_NOISE_STATE_EXTERNAL
;
2364 if (sampling_in_progress
)
2367 pi
->phynoise_now
= pi
->sh
->now
;
2369 if (pi
->phy_fixed_noise
) {
2371 pi
->nphy_noise_win
[WL_ANT_IDX_1
][pi
->nphy_noise_index
] =
2372 PHY_NOISE_FIXED_VAL_NPHY
;
2373 pi
->nphy_noise_win
[WL_ANT_IDX_2
][pi
->nphy_noise_index
] =
2374 PHY_NOISE_FIXED_VAL_NPHY
;
2375 pi
->nphy_noise_index
= MODINC_POW2(pi
->nphy_noise_index
,
2376 PHY_NOISE_WINDOW_SZ
);
2377 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2379 noise_dbm
= PHY_NOISE_FIXED_VAL
;
2382 wait_for_intr
= false;
2387 if (!pi
->phynoise_polling
2388 || (reason
== PHY_NOISE_SAMPLE_EXTERNAL
)) {
2389 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_JSSI_0
, 0);
2390 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
, 0);
2391 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
, 0);
2392 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
, 0);
2393 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
, 0);
2395 bcma_set32(pi
->d11core
, D11REGOFFS(maccommand
),
2398 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2399 wlc_lcnphy_deaf_mode(pi
, (bool) 0);
2400 noise_dbm
= (s8
) wlc_lcnphy_rx_signal_power(pi
, 20);
2401 wlc_lcnphy_deaf_mode(pi
, (bool) 1);
2402 wlapi_enable_mac(pi
->sh
->physhim
);
2403 wait_for_intr
= false;
2405 } else if (ISNPHY(pi
)) {
2406 if (!pi
->phynoise_polling
2407 || (reason
== PHY_NOISE_SAMPLE_EXTERNAL
)) {
2409 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
, 0);
2410 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
, 0);
2411 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
, 0);
2412 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
, 0);
2414 bcma_set32(pi
->d11core
, D11REGOFFS(maccommand
),
2417 struct phy_iq_est est
[PHY_CORE_MAX
];
2418 u32 cmplx_pwr
[PHY_CORE_MAX
];
2419 s8 noise_dbm_ant
[PHY_CORE_MAX
];
2420 u16 log_num_samps
, num_samps
, classif_state
= 0;
2425 memset((u8
*) est
, 0, sizeof(est
));
2426 memset((u8
*) cmplx_pwr
, 0, sizeof(cmplx_pwr
));
2427 memset((u8
*) noise_dbm_ant
, 0, sizeof(noise_dbm_ant
));
2429 log_num_samps
= PHY_NOISE_SAMPLE_LOG_NUM_NPHY
;
2430 num_samps
= 1 << log_num_samps
;
2432 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2433 classif_state
= wlc_phy_classifier_nphy(pi
, 0, 0);
2434 wlc_phy_classifier_nphy(pi
, 3, 0);
2435 wlc_phy_rx_iq_est_nphy(pi
, est
, num_samps
, wait_time
,
2437 wlc_phy_classifier_nphy(pi
, (0x7 << 0), classif_state
);
2438 wlapi_enable_mac(pi
->sh
->physhim
);
2440 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++)
2441 cmplx_pwr
[i
] = (est
[i
].i_pwr
+ est
[i
].q_pwr
) >>
2444 wlc_phy_noise_calc_phy(pi
, cmplx_pwr
, noise_dbm_ant
);
2446 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2447 pi
->nphy_noise_win
[i
][pi
->nphy_noise_index
] =
2450 if (noise_dbm_ant
[i
] > noise_dbm
)
2451 noise_dbm
= noise_dbm_ant
[i
];
2453 pi
->nphy_noise_index
= MODINC_POW2(pi
->nphy_noise_index
,
2454 PHY_NOISE_WINDOW_SZ
);
2456 wait_for_intr
= false;
2463 wlc_phy_noise_cb(pi
, ch
, noise_dbm
);
2467 void wlc_phy_noise_sample_request_external(struct brcms_phy_pub
*pih
)
2471 channel
= CHSPEC_CHANNEL(wlc_phy_chanspec_get(pih
));
2473 wlc_phy_noise_sample_request(pih
, PHY_NOISE_SAMPLE_EXTERNAL
, channel
);
2476 static const s8 lcnphy_gain_index_offset_for_pkt_rssi
[] = {
2517 void wlc_phy_compute_dB(u32
*cmplx_pwr
, s8
*p_cmplx_pwr_dB
, u8 core
)
2519 u8 msb
, secondmsb
, i
;
2522 for (i
= 0; i
< core
; i
++) {
2527 secondmsb
= (u8
) ((tmp
>> (--msb
- 1)) & 1);
2528 p_cmplx_pwr_dB
[i
] = (s8
) (3 * msb
+ 2 * secondmsb
);
2532 int wlc_phy_rssi_compute(struct brcms_phy_pub
*pih
,
2533 struct d11rxhdr
*rxh
)
2535 int rssi
= rxh
->PhyRxStatus_1
& PRXS1_JSSI_MASK
;
2536 uint radioid
= pih
->radioid
;
2537 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2539 if ((pi
->sh
->corerev
>= 11)
2540 && !(rxh
->RxStatus2
& RXS_PHYRXST_VALID
)) {
2541 rssi
= BRCMS_RSSI_INVALID
;
2546 u8 gidx
= (rxh
->PhyRxStatus_2
& 0xFC00) >> 10;
2547 struct brcms_phy_lcnphy
*pi_lcn
= pi
->u
.pi_lcnphy
;
2552 rssi
= rssi
+ lcnphy_gain_index_offset_for_pkt_rssi
[gidx
];
2553 if ((rssi
> -46) && (gidx
> 18))
2556 rssi
= rssi
+ pi_lcn
->lcnphy_pkteng_rssi_slope
;
2565 } else if (radioid
== BCM2055_ID
|| radioid
== BCM2056_ID
2566 || radioid
== BCM2057_ID
) {
2567 rssi
= wlc_phy_rssi_compute_nphy(pi
, rxh
);
2574 void wlc_phy_freqtrack_start(struct brcms_phy_pub
*pih
)
2579 void wlc_phy_freqtrack_end(struct brcms_phy_pub
*pih
)
2584 void wlc_phy_set_deaf(struct brcms_phy_pub
*ppi
, bool user_flag
)
2586 struct brcms_phy
*pi
;
2587 pi
= (struct brcms_phy
*) ppi
;
2590 wlc_lcnphy_deaf_mode(pi
, true);
2591 else if (ISNPHY(pi
))
2592 wlc_nphy_deaf_mode(pi
, true);
2595 void wlc_phy_watchdog(struct brcms_phy_pub
*pih
)
2597 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2598 bool delay_phy_cal
= false;
2601 if (!pi
->watchdog_override
)
2604 if (!(SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)))
2605 wlc_phy_noise_sample_request((struct brcms_phy_pub
*) pi
,
2606 PHY_NOISE_SAMPLE_MON
,
2610 if (pi
->phynoise_state
&& (pi
->sh
->now
- pi
->phynoise_now
) > 5)
2611 pi
->phynoise_state
= 0;
2613 if ((!pi
->phycal_txpower
) ||
2614 ((pi
->sh
->now
- pi
->phycal_txpower
) >= pi
->sh
->fast_timer
)) {
2616 if (!SCAN_INPROG_PHY(pi
) && wlc_phy_cal_txpower_recalc_sw(pi
))
2617 pi
->phycal_txpower
= pi
->sh
->now
;
2620 if ((SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)
2621 || ASSOC_INPROG_PHY(pi
)))
2624 if (ISNPHY(pi
) && !pi
->disable_percal
&& !delay_phy_cal
) {
2626 if ((pi
->nphy_perical
!= PHY_PERICAL_DISABLE
) &&
2627 (pi
->nphy_perical
!= PHY_PERICAL_MANUAL
) &&
2628 ((pi
->sh
->now
- pi
->nphy_perical_last
) >=
2629 pi
->sh
->glacial_timer
))
2630 wlc_phy_cal_perical((struct brcms_phy_pub
*) pi
,
2631 PHY_PERICAL_WATCHDOG
);
2633 wlc_phy_txpwr_papd_cal_nphy(pi
);
2637 if (pi
->phy_forcecal
||
2638 ((pi
->sh
->now
- pi
->phy_lastcal
) >=
2639 pi
->sh
->glacial_timer
)) {
2640 if (!(SCAN_RM_IN_PROGRESS(pi
) || ASSOC_INPROG_PHY(pi
)))
2641 wlc_lcnphy_calib_modes(
2643 LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL
);
2645 (SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)
2646 || ASSOC_INPROG_PHY(pi
)
2647 || pi
->carrier_suppr_disable
2648 || pi
->disable_percal
))
2649 wlc_lcnphy_calib_modes(pi
,
2650 PHY_PERICAL_WATCHDOG
);
2655 void wlc_phy_BSSinit(struct brcms_phy_pub
*pih
, bool bonlyap
, int rssi
)
2657 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2661 for (i
= 0; i
< MA_WINDOW_SZ
; i
++)
2662 pi
->sh
->phy_noise_window
[i
] = (s8
) (rssi
& 0xff);
2664 for (i
= 0; i
< MA_WINDOW_SZ
; i
++)
2665 pi
->sh
->phy_noise_window
[i
] =
2666 PHY_NOISE_FIXED_VAL_LCNPHY
;
2668 pi
->sh
->phy_noise_index
= 0;
2670 for (i
= 0; i
< PHY_NOISE_WINDOW_SZ
; i
++) {
2671 for (k
= WL_ANT_IDX_1
; k
< WL_ANT_RX_MAX
; k
++)
2672 pi
->nphy_noise_win
[k
][i
] = PHY_NOISE_FIXED_VAL_NPHY
;
2674 pi
->nphy_noise_index
= 0;
2678 wlc_phy_papd_decode_epsilon(u32 epsilon
, s32
*eps_real
, s32
*eps_imag
)
2680 *eps_imag
= (epsilon
>> 13);
2681 if (*eps_imag
> 0xfff)
2682 *eps_imag
-= 0x2000;
2684 *eps_real
= (epsilon
& 0x1fff);
2685 if (*eps_real
> 0xfff)
2686 *eps_real
-= 0x2000;
2689 void wlc_phy_cal_perical_mphase_reset(struct brcms_phy
*pi
)
2691 wlapi_del_timer(pi
->phycal_timer
);
2693 pi
->cal_type_override
= PHY_PERICAL_AUTO
;
2694 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_IDLE
;
2695 pi
->mphase_txcal_cmdidx
= 0;
2699 wlc_phy_cal_perical_mphase_schedule(struct brcms_phy
*pi
, uint delay
)
2702 if ((pi
->nphy_perical
!= PHY_PERICAL_MPHASE
) &&
2703 (pi
->nphy_perical
!= PHY_PERICAL_MANUAL
))
2706 wlapi_del_timer(pi
->phycal_timer
);
2708 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_INIT
;
2709 wlapi_add_timer(pi
->phycal_timer
, delay
, 0);
2712 void wlc_phy_cal_perical(struct brcms_phy_pub
*pih
, u8 reason
)
2714 s16 nphy_currtemp
= 0;
2716 bool do_periodic_cal
= true;
2717 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2722 if ((pi
->nphy_perical
== PHY_PERICAL_DISABLE
) ||
2723 (pi
->nphy_perical
== PHY_PERICAL_MANUAL
))
2727 case PHY_PERICAL_DRIVERUP
:
2730 case PHY_PERICAL_PHYINIT
:
2731 if (pi
->nphy_perical
== PHY_PERICAL_MPHASE
) {
2732 if (PHY_PERICAL_MPHASE_PENDING(pi
))
2733 wlc_phy_cal_perical_mphase_reset(pi
);
2735 wlc_phy_cal_perical_mphase_schedule(
2737 PHY_PERICAL_INIT_DELAY
);
2741 case PHY_PERICAL_JOIN_BSS
:
2742 case PHY_PERICAL_START_IBSS
:
2743 case PHY_PERICAL_UP_BSS
:
2744 if ((pi
->nphy_perical
== PHY_PERICAL_MPHASE
) &&
2745 PHY_PERICAL_MPHASE_PENDING(pi
))
2746 wlc_phy_cal_perical_mphase_reset(pi
);
2748 pi
->first_cal_after_assoc
= true;
2750 pi
->cal_type_override
= PHY_PERICAL_FULL
;
2752 if (pi
->phycal_tempdelta
)
2753 pi
->nphy_lastcal_temp
= wlc_phy_tempsense_nphy(pi
);
2755 wlc_phy_cal_perical_nphy_run(pi
, PHY_PERICAL_FULL
);
2758 case PHY_PERICAL_WATCHDOG
:
2759 if (pi
->phycal_tempdelta
) {
2760 nphy_currtemp
= wlc_phy_tempsense_nphy(pi
);
2762 (nphy_currtemp
> pi
->nphy_lastcal_temp
) ?
2763 nphy_currtemp
- pi
->nphy_lastcal_temp
:
2764 pi
->nphy_lastcal_temp
- nphy_currtemp
;
2766 if ((delta_temp
< (s16
) pi
->phycal_tempdelta
) &&
2767 (pi
->nphy_txiqlocal_chanspec
==
2768 pi
->radio_chanspec
))
2769 do_periodic_cal
= false;
2771 pi
->nphy_lastcal_temp
= nphy_currtemp
;
2774 if (do_periodic_cal
) {
2775 if (pi
->nphy_perical
== PHY_PERICAL_MPHASE
) {
2776 if (!PHY_PERICAL_MPHASE_PENDING(pi
))
2777 wlc_phy_cal_perical_mphase_schedule(
2779 PHY_PERICAL_WDOG_DELAY
);
2780 } else if (pi
->nphy_perical
== PHY_PERICAL_SPHASE
)
2781 wlc_phy_cal_perical_nphy_run(pi
,
2790 void wlc_phy_cal_perical_mphase_restart(struct brcms_phy
*pi
)
2792 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_INIT
;
2793 pi
->mphase_txcal_cmdidx
= 0;
2796 u8
wlc_phy_nbits(s32 value
)
2801 abs_val
= abs(value
);
2802 while ((abs_val
>> nbits
) > 0)
2808 void wlc_phy_stf_chain_init(struct brcms_phy_pub
*pih
, u8 txchain
, u8 rxchain
)
2810 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2812 pi
->sh
->hw_phytxchain
= txchain
;
2813 pi
->sh
->hw_phyrxchain
= rxchain
;
2814 pi
->sh
->phytxchain
= txchain
;
2815 pi
->sh
->phyrxchain
= rxchain
;
2816 pi
->pubpi
.phy_corenum
= (u8
)hweight8(pi
->sh
->phyrxchain
);
2819 void wlc_phy_stf_chain_set(struct brcms_phy_pub
*pih
, u8 txchain
, u8 rxchain
)
2821 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2823 pi
->sh
->phytxchain
= txchain
;
2826 wlc_phy_rxcore_setstate_nphy(pih
, rxchain
);
2828 pi
->pubpi
.phy_corenum
= (u8
)hweight8(pi
->sh
->phyrxchain
);
2831 void wlc_phy_stf_chain_get(struct brcms_phy_pub
*pih
, u8
*txchain
, u8
*rxchain
)
2833 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2835 *txchain
= pi
->sh
->phytxchain
;
2836 *rxchain
= pi
->sh
->phyrxchain
;
2839 u8
wlc_phy_stf_chain_active_get(struct brcms_phy_pub
*pih
)
2843 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2845 active_bitmap
= (pi
->phy_txcore_heatedup
) ? 0x31 : 0x33;
2847 if (!pi
->watchdog_override
)
2848 return active_bitmap
;
2850 if (NREV_GE(pi
->pubpi
.phy_rev
, 6)) {
2851 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2852 nphy_currtemp
= wlc_phy_tempsense_nphy(pi
);
2853 wlapi_enable_mac(pi
->sh
->physhim
);
2855 if (!pi
->phy_txcore_heatedup
) {
2856 if (nphy_currtemp
>= pi
->phy_txcore_disable_temp
) {
2857 active_bitmap
&= 0xFD;
2858 pi
->phy_txcore_heatedup
= true;
2861 if (nphy_currtemp
<= pi
->phy_txcore_enable_temp
) {
2862 active_bitmap
|= 0x2;
2863 pi
->phy_txcore_heatedup
= false;
2868 return active_bitmap
;
2871 s8
wlc_phy_stf_ssmode_get(struct brcms_phy_pub
*pih
, u16 chanspec
)
2873 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2874 u8 siso_mcs_id
, cdd_mcs_id
;
2877 (CHSPEC_IS40(chanspec
)) ? TXP_FIRST_MCS_40_SISO
:
2878 TXP_FIRST_MCS_20_SISO
;
2880 (CHSPEC_IS40(chanspec
)) ? TXP_FIRST_MCS_40_CDD
:
2881 TXP_FIRST_MCS_20_CDD
;
2883 if (pi
->tx_power_target
[siso_mcs_id
] >
2884 (pi
->tx_power_target
[cdd_mcs_id
] + 12))
2885 return PHY_TXC1_MODE_SISO
;
2887 return PHY_TXC1_MODE_CDD
;
2890 const u8
*wlc_phy_get_ofdm_rate_lookup(void)
2892 return ofdm_rate_lookup
;
2895 void wlc_lcnphy_epa_switch(struct brcms_phy
*pi
, bool mode
)
2897 if ((pi
->sh
->chip
== BCM4313_CHIP_ID
) &&
2898 (pi
->sh
->boardflags
& BFL_FEM
)) {
2901 txant
= wlapi_bmac_get_txant(pi
->sh
->physhim
);
2903 mod_phy_reg(pi
, 0x44d, (0x1 << 2), (1) << 2);
2905 mod_phy_reg(pi
, 0x44c, (0x1 << 2), (1) << 2);
2908 ai_cc_reg(pi
->sh
->sih
,
2909 offsetof(struct chipcregs
, gpiocontrol
),
2911 ai_cc_reg(pi
->sh
->sih
,
2912 offsetof(struct chipcregs
, gpioout
),
2914 ai_cc_reg(pi
->sh
->sih
,
2915 offsetof(struct chipcregs
, gpioouten
),
2918 mod_phy_reg(pi
, 0x44c, (0x1 << 2), (0) << 2);
2920 mod_phy_reg(pi
, 0x44d, (0x1 << 2), (0) << 2);
2922 ai_cc_reg(pi
->sh
->sih
,
2923 offsetof(struct chipcregs
, gpioout
),
2925 ai_cc_reg(pi
->sh
->sih
,
2926 offsetof(struct chipcregs
, gpioouten
),
2928 ai_cc_reg(pi
->sh
->sih
,
2929 offsetof(struct chipcregs
, gpiocontrol
),
2935 void wlc_phy_ldpc_override_set(struct brcms_phy_pub
*ppi
, bool ldpc
)
2941 wlc_phy_get_pwrdet_offsets(struct brcms_phy
*pi
, s8
*cckoffset
, s8
*ofdmoffset
)
2947 s8
wlc_phy_upd_rssi_offset(struct brcms_phy
*pi
, s8 rssi
, u16 chanspec
)
2953 bool wlc_phy_txpower_ipa_ison(struct brcms_phy_pub
*ppi
)
2955 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2958 return wlc_phy_n_txpower_ipa_ison(pi
);