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 struct si_info
*sii
= container_of(pi
->sh
->sih
, struct si_info
, pub
);
203 if ((D11REV_GE(pi
->sh
->corerev
, 24)) ||
204 (D11REV_IS(pi
->sh
->corerev
, 22)
205 && (pi
->pubpi
.phy_type
!= PHY_TYPE_SSN
))) {
207 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), addr
);
208 bcma_write16(pi
->d11core
, D11REGOFFS(radioregdata
), val
);
210 bcma_wflush16(pi
->d11core
, D11REGOFFS(phy4waddr
), addr
);
211 bcma_write16(pi
->d11core
, D11REGOFFS(phy4wdatalo
), val
);
214 if ((sii
->icbus
->hosttype
== BCMA_HOSTTYPE_PCI
) &&
215 (++pi
->phy_wreg
>= pi
->phy_wreg_limit
)) {
216 (void)bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
221 static u32
read_radio_id(struct brcms_phy
*pi
)
225 if (D11REV_GE(pi
->sh
->corerev
, 24)) {
228 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 0);
229 b0
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
230 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 1);
231 b1
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
232 bcma_wflush16(pi
->d11core
, D11REGOFFS(radioregaddr
), 2);
233 b2
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(radioregdata
));
235 id
= ((b0
& 0xf) << 28) | (((b2
<< 8) | b1
) << 12) | ((b0
>> 4)
238 bcma_wflush16(pi
->d11core
, D11REGOFFS(phy4waddr
), RADIO_IDCODE
);
239 id
= (u32
) bcma_read16(pi
->d11core
, D11REGOFFS(phy4wdatalo
));
240 id
|= (u32
) bcma_read16(pi
->d11core
,
241 D11REGOFFS(phy4wdatahi
)) << 16;
247 void and_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
251 rval
= read_radio_reg(pi
, addr
);
252 write_radio_reg(pi
, addr
, (rval
& val
));
255 void or_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
259 rval
= read_radio_reg(pi
, addr
);
260 write_radio_reg(pi
, addr
, (rval
| val
));
263 void xor_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
)
267 rval
= read_radio_reg(pi
, addr
);
268 write_radio_reg(pi
, addr
, (rval
^ mask
));
271 void mod_radio_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
, u16 val
)
275 rval
= read_radio_reg(pi
, addr
);
276 write_radio_reg(pi
, addr
, (rval
& ~mask
) | (val
& mask
));
279 void write_phy_channel_reg(struct brcms_phy
*pi
, uint val
)
281 bcma_write16(pi
->d11core
, D11REGOFFS(phychannel
), val
);
284 u16
read_phy_reg(struct brcms_phy
*pi
, u16 addr
)
286 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
289 return bcma_read16(pi
->d11core
, D11REGOFFS(phyregdata
));
292 void write_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
294 #ifdef CONFIG_BCM47XX
295 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
296 bcma_write16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
298 (void)bcma_read16(pi
->d11core
, D11REGOFFS(phyregdata
));
300 struct si_info
*sii
= container_of(pi
->sh
->sih
, struct si_info
, pub
);
302 bcma_write32(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
| (val
<< 16));
303 if ((sii
->icbus
->hosttype
== BCMA_HOSTTYPE_PCI
) &&
304 (++pi
->phy_wreg
>= pi
->phy_wreg_limit
)) {
306 (void)bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
311 void and_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
313 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
314 bcma_mask16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
318 void or_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 val
)
320 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
321 bcma_set16(pi
->d11core
, D11REGOFFS(phyregdata
), val
);
325 void mod_phy_reg(struct brcms_phy
*pi
, u16 addr
, u16 mask
, u16 val
)
328 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
), addr
);
329 bcma_maskset16(pi
->d11core
, D11REGOFFS(phyregdata
), ~mask
, val
);
333 static void wlc_set_phy_uninitted(struct brcms_phy
*pi
)
337 pi
->initialized
= false;
340 pi
->nrssi_table_delta
= 0x7fffffff;
342 pi
->mintxbias
= 0xffff;
345 pi
->phy_spuravoid
= SPURAVOID_DISABLE
;
347 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)
348 && NREV_LT(pi
->pubpi
.phy_rev
, 7))
349 pi
->phy_spuravoid
= SPURAVOID_AUTO
;
351 pi
->nphy_papd_skip
= 0;
352 pi
->nphy_papd_epsilon_offset
[0] = 0xf588;
353 pi
->nphy_papd_epsilon_offset
[1] = 0xf588;
354 pi
->nphy_txpwr_idx
[0] = 128;
355 pi
->nphy_txpwr_idx
[1] = 128;
356 pi
->nphy_txpwrindex
[0].index_internal
= 40;
357 pi
->nphy_txpwrindex
[1].index_internal
= 40;
360 pi
->phy_spuravoid
= SPURAVOID_AUTO
;
362 pi
->radiopwr
= 0xffff;
363 for (i
= 0; i
< STATIC_NUM_RF
; i
++) {
364 for (j
= 0; j
< STATIC_NUM_BB
; j
++)
365 pi
->stats_11b_txpower
[i
][j
] = -1;
369 struct shared_phy
*wlc_phy_shared_attach(struct shared_phy_params
*shp
)
371 struct shared_phy
*sh
;
373 sh
= kzalloc(sizeof(struct shared_phy
), GFP_ATOMIC
);
378 sh
->physhim
= shp
->physhim
;
379 sh
->unit
= shp
->unit
;
380 sh
->corerev
= shp
->corerev
;
384 sh
->chip
= shp
->chip
;
385 sh
->chiprev
= shp
->chiprev
;
386 sh
->chippkg
= shp
->chippkg
;
387 sh
->sromrev
= shp
->sromrev
;
388 sh
->boardtype
= shp
->boardtype
;
389 sh
->boardrev
= shp
->boardrev
;
390 sh
->boardflags
= shp
->boardflags
;
391 sh
->boardflags2
= shp
->boardflags2
;
393 sh
->fast_timer
= PHY_SW_TIMER_FAST
;
394 sh
->slow_timer
= PHY_SW_TIMER_SLOW
;
395 sh
->glacial_timer
= PHY_SW_TIMER_GLACIAL
;
397 sh
->rssi_mode
= RSSI_ANT_MERGE_MAX
;
402 static void wlc_phy_timercb_phycal(struct brcms_phy
*pi
)
406 if (PHY_PERICAL_MPHASE_PENDING(pi
)) {
408 wlc_phy_cal_perical_mphase_reset(pi
);
412 if (SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)) {
415 wlc_phy_cal_perical_mphase_restart(pi
);
417 wlc_phy_cal_perical_nphy_run(pi
, PHY_PERICAL_AUTO
);
418 wlapi_add_timer(pi
->phycal_timer
, delay
, 0);
424 static u32
wlc_phy_get_radio_ver(struct brcms_phy
*pi
)
428 ver
= read_radio_id(pi
);
433 struct brcms_phy_pub
*
434 wlc_phy_attach(struct shared_phy
*sh
, struct bcma_device
*d11core
,
435 int bandtype
, struct wiphy
*wiphy
)
437 struct brcms_phy
*pi
;
443 if (D11REV_IS(sh
->corerev
, 4))
444 sflags
= SISF_2G_PHY
| SISF_5G_PHY
;
446 sflags
= bcma_aread32(d11core
, BCMA_IOST
);
448 if (bandtype
== BRCM_BAND_5G
) {
449 if ((sflags
& (SISF_5G_PHY
| SISF_DB_PHY
)) == 0)
454 if ((sflags
& SISF_DB_PHY
) && pi
) {
455 wlapi_bmac_corereset(pi
->sh
->physhim
, pi
->pubpi
.coreflags
);
457 return &pi
->pubpi_ro
;
460 pi
= kzalloc(sizeof(struct brcms_phy
), GFP_ATOMIC
);
464 pi
->d11core
= d11core
;
466 pi
->phy_init_por
= true;
467 pi
->phy_wreg_limit
= PHY_WREG_LIMIT
;
469 pi
->txpwr_percent
= 100;
471 pi
->do_initcal
= true;
473 pi
->phycal_tempdelta
= 0;
475 if (bandtype
== BRCM_BAND_2G
&& (sflags
& SISF_2G_PHY
))
476 pi
->pubpi
.coreflags
= SICF_GMODE
;
478 wlapi_bmac_corereset(pi
->sh
->physhim
, pi
->pubpi
.coreflags
);
479 phyversion
= bcma_read16(pi
->d11core
, D11REGOFFS(phyversion
));
481 pi
->pubpi
.phy_type
= PHY_TYPE(phyversion
);
482 pi
->pubpi
.phy_rev
= phyversion
& PV_PV_MASK
;
484 if (pi
->pubpi
.phy_type
== PHY_TYPE_LCNXN
) {
485 pi
->pubpi
.phy_type
= PHY_TYPE_N
;
486 pi
->pubpi
.phy_rev
+= LCNXN_BASEREV
;
488 pi
->pubpi
.phy_corenum
= PHY_CORE_NUM_2
;
489 pi
->pubpi
.ana_rev
= (phyversion
& PV_AV_MASK
) >> PV_AV_SHIFT
;
491 if (pi
->pubpi
.phy_type
!= PHY_TYPE_N
&&
492 pi
->pubpi
.phy_type
!= PHY_TYPE_LCN
)
495 if (bandtype
== BRCM_BAND_5G
) {
498 } else if (!ISNPHY(pi
) && !ISLCNPHY(pi
)) {
502 wlc_phy_anacore((struct brcms_phy_pub
*) pi
, ON
);
504 idcode
= wlc_phy_get_radio_ver(pi
);
506 (idcode
& IDCODE_ID_MASK
) >> IDCODE_ID_SHIFT
;
508 (idcode
& IDCODE_REV_MASK
) >> IDCODE_REV_SHIFT
;
510 (idcode
& IDCODE_VER_MASK
) >> IDCODE_VER_SHIFT
;
511 if (!VALID_RADIO(pi
, pi
->pubpi
.radioid
))
514 wlc_phy_switch_radio((struct brcms_phy_pub
*) pi
, OFF
);
516 wlc_set_phy_uninitted(pi
);
518 pi
->bw
= WL_CHANSPEC_BW_20
;
519 pi
->radio_chanspec
= (bandtype
== BRCM_BAND_2G
) ?
520 ch20mhz_chspec(1) : ch20mhz_chspec(36);
522 pi
->rxiq_samps
= PHY_NOISE_SAMPLE_LOG_NUM_NPHY
;
523 pi
->rxiq_antsel
= ANT_RX_DIV_DEF
;
525 pi
->watchdog_override
= true;
527 pi
->cal_type_override
= PHY_PERICAL_AUTO
;
529 pi
->nphy_saved_noisevars
.bufcount
= 0;
532 pi
->min_txpower
= PHY_TXPWR_MIN_NPHY
;
534 pi
->min_txpower
= PHY_TXPWR_MIN
;
536 pi
->sh
->phyrxchain
= 0x3;
538 pi
->rx2tx_biasentry
= -1;
540 pi
->phy_txcore_disable_temp
= PHY_CHAIN_TX_DISABLE_TEMP
;
541 pi
->phy_txcore_enable_temp
=
542 PHY_CHAIN_TX_DISABLE_TEMP
- PHY_HYSTERESIS_DELTATEMP
;
543 pi
->phy_tempsense_offset
= 0;
544 pi
->phy_txcore_heatedup
= false;
546 pi
->nphy_lastcal_temp
= -50;
548 pi
->phynoise_polling
= true;
549 if (ISNPHY(pi
) || ISLCNPHY(pi
))
550 pi
->phynoise_polling
= false;
552 for (i
= 0; i
< TXP_NUM_RATES
; i
++) {
553 pi
->txpwr_limit
[i
] = BRCMS_TXPWR_MAX
;
554 pi
->txpwr_env_limit
[i
] = BRCMS_TXPWR_MAX
;
555 pi
->tx_user_target
[i
] = BRCMS_TXPWR_MAX
;
558 pi
->radiopwr_override
= RADIOPWR_OVERRIDE_DEF
;
560 pi
->user_txpwr_at_rfport
= false;
564 pi
->phycal_timer
= wlapi_init_timer(pi
->sh
->physhim
,
565 wlc_phy_timercb_phycal
,
567 if (!pi
->phycal_timer
)
570 if (!wlc_phy_attach_nphy(pi
))
573 } else if (ISLCNPHY(pi
)) {
574 if (!wlc_phy_attach_lcnphy(pi
))
580 pi
->next
= pi
->sh
->phy_head
;
583 memcpy(&pi
->pubpi_ro
, &pi
->pubpi
, sizeof(struct brcms_phy_pub
));
585 return &pi
->pubpi_ro
;
592 void wlc_phy_detach(struct brcms_phy_pub
*pih
)
594 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
600 if (pi
->phycal_timer
) {
601 wlapi_free_timer(pi
->phycal_timer
);
602 pi
->phycal_timer
= NULL
;
605 if (pi
->sh
->phy_head
== pi
)
606 pi
->sh
->phy_head
= pi
->next
;
607 else if (pi
->sh
->phy_head
->next
== pi
)
608 pi
->sh
->phy_head
->next
= NULL
;
610 if (pi
->pi_fptr
.detach
)
611 (pi
->pi_fptr
.detach
)(pi
);
618 wlc_phy_get_phyversion(struct brcms_phy_pub
*pih
, u16
*phytype
, u16
*phyrev
,
619 u16
*radioid
, u16
*radiover
)
621 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
622 *phytype
= (u16
) pi
->pubpi
.phy_type
;
623 *phyrev
= (u16
) pi
->pubpi
.phy_rev
;
624 *radioid
= pi
->pubpi
.radioid
;
625 *radiover
= pi
->pubpi
.radiorev
;
630 bool wlc_phy_get_encore(struct brcms_phy_pub
*pih
)
632 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
633 return pi
->pubpi
.abgphy_encore
;
636 u32
wlc_phy_get_coreflags(struct brcms_phy_pub
*pih
)
638 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
639 return pi
->pubpi
.coreflags
;
642 void wlc_phy_anacore(struct brcms_phy_pub
*pih
, bool on
)
644 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
648 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
649 write_phy_reg(pi
, 0xa6, 0x0d);
650 write_phy_reg(pi
, 0x8f, 0x0);
651 write_phy_reg(pi
, 0xa7, 0x0d);
652 write_phy_reg(pi
, 0xa5, 0x0);
654 write_phy_reg(pi
, 0xa5, 0x0);
657 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
658 write_phy_reg(pi
, 0x8f, 0x07ff);
659 write_phy_reg(pi
, 0xa6, 0x0fd);
660 write_phy_reg(pi
, 0xa5, 0x07ff);
661 write_phy_reg(pi
, 0xa7, 0x0fd);
663 write_phy_reg(pi
, 0xa5, 0x7fff);
666 } else if (ISLCNPHY(pi
)) {
668 and_phy_reg(pi
, 0x43b,
669 ~((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
671 or_phy_reg(pi
, 0x43c,
672 (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
673 or_phy_reg(pi
, 0x43b,
674 (0x1 << 0) | (0x1 << 1) | (0x1 << 2));
679 u32
wlc_phy_clk_bwbits(struct brcms_phy_pub
*pih
)
681 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
683 u32 phy_bw_clkbits
= 0;
685 if (pi
&& (ISNPHY(pi
) || ISLCNPHY(pi
))) {
687 case WL_CHANSPEC_BW_10
:
688 phy_bw_clkbits
= SICF_BW10
;
690 case WL_CHANSPEC_BW_20
:
691 phy_bw_clkbits
= SICF_BW20
;
693 case WL_CHANSPEC_BW_40
:
694 phy_bw_clkbits
= SICF_BW40
;
701 return phy_bw_clkbits
;
704 void wlc_phy_por_inform(struct brcms_phy_pub
*ppi
)
706 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
708 pi
->phy_init_por
= true;
711 void wlc_phy_edcrs_lock(struct brcms_phy_pub
*pih
, bool lock
)
713 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
715 pi
->edcrs_threshold_lock
= lock
;
717 write_phy_reg(pi
, 0x22c, 0x46b);
718 write_phy_reg(pi
, 0x22d, 0x46b);
719 write_phy_reg(pi
, 0x22e, 0x3c0);
720 write_phy_reg(pi
, 0x22f, 0x3c0);
723 void wlc_phy_initcal_enable(struct brcms_phy_pub
*pih
, bool initcal
)
725 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
727 pi
->do_initcal
= initcal
;
730 void wlc_phy_hw_clk_state_upd(struct brcms_phy_pub
*pih
, bool newstate
)
732 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
737 pi
->sh
->clk
= newstate
;
740 void wlc_phy_hw_state_upd(struct brcms_phy_pub
*pih
, bool newstate
)
742 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
747 pi
->sh
->up
= newstate
;
750 void wlc_phy_init(struct brcms_phy_pub
*pih
, u16 chanspec
)
753 void (*phy_init
)(struct brcms_phy
*) = NULL
;
754 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
756 if (pi
->init_in_progress
)
759 pi
->init_in_progress
= true;
761 pi
->radio_chanspec
= chanspec
;
763 mc
= bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
764 if (WARN(mc
& MCTL_EN_MAC
, "HW error MAC running on init"))
767 if (!(pi
->measure_hold
& PHY_HOLD_FOR_SCAN
))
768 pi
->measure_hold
|= PHY_HOLD_FOR_NOT_ASSOC
;
770 if (WARN(!(bcma_aread32(pi
->d11core
, BCMA_IOST
) & SISF_FCLKA
),
771 "HW error SISF_FCLKA\n"))
774 phy_init
= pi
->pi_fptr
.init
;
776 if (phy_init
== NULL
)
779 wlc_phy_anacore(pih
, ON
);
781 if (CHSPEC_BW(pi
->radio_chanspec
) != pi
->bw
)
782 wlapi_bmac_bw_set(pi
->sh
->physhim
,
783 CHSPEC_BW(pi
->radio_chanspec
));
785 pi
->nphy_gain_boost
= true;
787 wlc_phy_switch_radio((struct brcms_phy_pub
*) pi
, ON
);
791 pi
->phy_init_por
= false;
793 if (D11REV_IS(pi
->sh
->corerev
, 11) || D11REV_IS(pi
->sh
->corerev
, 12))
794 wlc_phy_do_dummy_tx(pi
, true, OFF
);
797 wlc_phy_txpower_update_shm(pi
);
799 wlc_phy_ant_rxdiv_set((struct brcms_phy_pub
*) pi
, pi
->sh
->rx_antdiv
);
801 pi
->init_in_progress
= false;
804 void wlc_phy_cal_init(struct brcms_phy_pub
*pih
)
806 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
807 void (*cal_init
)(struct brcms_phy
*) = NULL
;
809 if (WARN((bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) &
810 MCTL_EN_MAC
) != 0, "HW error: MAC enabled during phy cal\n"))
813 if (!pi
->initialized
) {
814 cal_init
= pi
->pi_fptr
.calinit
;
818 pi
->initialized
= true;
822 int wlc_phy_down(struct brcms_phy_pub
*pih
)
824 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
828 && !wlapi_del_timer(pi
->phycal_timer
))
831 pi
->nphy_iqcal_chanspec_2G
= 0;
832 pi
->nphy_iqcal_chanspec_5G
= 0;
838 wlc_phy_table_addr(struct brcms_phy
*pi
, uint tbl_id
, uint tbl_offset
,
839 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
841 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
843 pi
->tbl_data_hi
= tblDataHi
;
844 pi
->tbl_data_lo
= tblDataLo
;
846 if (pi
->sh
->chip
== BCMA_CHIP_ID_BCM43224
&&
847 pi
->sh
->chiprev
== 1) {
848 pi
->tbl_addr
= tblAddr
;
849 pi
->tbl_save_id
= tbl_id
;
850 pi
->tbl_save_offset
= tbl_offset
;
854 void wlc_phy_table_data_write(struct brcms_phy
*pi
, uint width
, u32 val
)
856 if ((pi
->sh
->chip
== BCMA_CHIP_ID_BCM43224
) &&
857 (pi
->sh
->chiprev
== 1) &&
858 (pi
->tbl_save_id
== NPHY_TBL_ID_ANTSWCTRLLUT
)) {
859 read_phy_reg(pi
, pi
->tbl_data_lo
);
861 write_phy_reg(pi
, pi
->tbl_addr
,
862 (pi
->tbl_save_id
<< 10) | pi
->tbl_save_offset
);
863 pi
->tbl_save_offset
++;
867 write_phy_reg(pi
, pi
->tbl_data_hi
, (u16
) (val
>> 16));
868 write_phy_reg(pi
, pi
->tbl_data_lo
, (u16
) val
);
870 write_phy_reg(pi
, pi
->tbl_data_lo
, (u16
) val
);
875 wlc_phy_write_table(struct brcms_phy
*pi
, const struct phytbl_info
*ptbl_info
,
876 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
879 uint tbl_id
= ptbl_info
->tbl_id
;
880 uint tbl_offset
= ptbl_info
->tbl_offset
;
881 uint tbl_width
= ptbl_info
->tbl_width
;
882 const u8
*ptbl_8b
= (const u8
*)ptbl_info
->tbl_ptr
;
883 const u16
*ptbl_16b
= (const u16
*)ptbl_info
->tbl_ptr
;
884 const u32
*ptbl_32b
= (const u32
*)ptbl_info
->tbl_ptr
;
886 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
888 for (idx
= 0; idx
< ptbl_info
->tbl_len
; idx
++) {
890 if ((pi
->sh
->chip
== BCMA_CHIP_ID_BCM43224
) &&
891 (pi
->sh
->chiprev
== 1) &&
892 (tbl_id
== NPHY_TBL_ID_ANTSWCTRLLUT
)) {
893 read_phy_reg(pi
, tblDataLo
);
895 write_phy_reg(pi
, tblAddr
,
896 (tbl_id
<< 10) | (tbl_offset
+ idx
));
899 if (tbl_width
== 32) {
900 write_phy_reg(pi
, tblDataHi
,
901 (u16
) (ptbl_32b
[idx
] >> 16));
902 write_phy_reg(pi
, tblDataLo
, (u16
) ptbl_32b
[idx
]);
903 } else if (tbl_width
== 16) {
904 write_phy_reg(pi
, tblDataLo
, ptbl_16b
[idx
]);
906 write_phy_reg(pi
, tblDataLo
, ptbl_8b
[idx
]);
912 wlc_phy_read_table(struct brcms_phy
*pi
, const struct phytbl_info
*ptbl_info
,
913 u16 tblAddr
, u16 tblDataHi
, u16 tblDataLo
)
916 uint tbl_id
= ptbl_info
->tbl_id
;
917 uint tbl_offset
= ptbl_info
->tbl_offset
;
918 uint tbl_width
= ptbl_info
->tbl_width
;
919 u8
*ptbl_8b
= (u8
*)ptbl_info
->tbl_ptr
;
920 u16
*ptbl_16b
= (u16
*)ptbl_info
->tbl_ptr
;
921 u32
*ptbl_32b
= (u32
*)ptbl_info
->tbl_ptr
;
923 write_phy_reg(pi
, tblAddr
, (tbl_id
<< 10) | tbl_offset
);
925 for (idx
= 0; idx
< ptbl_info
->tbl_len
; idx
++) {
927 if ((pi
->sh
->chip
== BCMA_CHIP_ID_BCM43224
) &&
928 (pi
->sh
->chiprev
== 1)) {
929 (void)read_phy_reg(pi
, tblDataLo
);
931 write_phy_reg(pi
, tblAddr
,
932 (tbl_id
<< 10) | (tbl_offset
+ idx
));
935 if (tbl_width
== 32) {
936 ptbl_32b
[idx
] = read_phy_reg(pi
, tblDataLo
);
937 ptbl_32b
[idx
] |= (read_phy_reg(pi
, tblDataHi
) << 16);
938 } else if (tbl_width
== 16) {
939 ptbl_16b
[idx
] = read_phy_reg(pi
, tblDataLo
);
941 ptbl_8b
[idx
] = (u8
) read_phy_reg(pi
, tblDataLo
);
947 wlc_phy_init_radio_regs_allbands(struct brcms_phy
*pi
,
948 struct radio_20xx_regs
*radioregs
)
953 if (radioregs
[i
].do_init
)
954 write_radio_reg(pi
, radioregs
[i
].address
,
955 (u16
) radioregs
[i
].init
);
958 } while (radioregs
[i
].address
!= 0xffff);
964 wlc_phy_init_radio_regs(struct brcms_phy
*pi
,
965 const struct radio_regs
*radioregs
,
972 if (CHSPEC_IS5G(pi
->radio_chanspec
)) {
973 if (radioregs
[i
].do_init_a
) {
976 address
| core_offset
,
977 (u16
) radioregs
[i
].init_a
);
978 if (ISNPHY(pi
) && (++count
% 4 == 0))
979 BRCMS_PHY_WAR_PR51571(pi
);
982 if (radioregs
[i
].do_init_g
) {
985 address
| core_offset
,
986 (u16
) radioregs
[i
].init_g
);
987 if (ISNPHY(pi
) && (++count
% 4 == 0))
988 BRCMS_PHY_WAR_PR51571(pi
);
993 } while (radioregs
[i
].address
!= 0xffff);
998 void wlc_phy_do_dummy_tx(struct brcms_phy
*pi
, bool ofdm
, bool pa_on
)
1000 #define DUMMY_PKT_LEN 20
1001 struct bcma_device
*core
= pi
->d11core
;
1003 u8 ofdmpkt
[DUMMY_PKT_LEN
] = {
1004 0xcc, 0x01, 0x02, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
1005 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
1007 u8 cckpkt
[DUMMY_PKT_LEN
] = {
1008 0x6e, 0x84, 0x0b, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00,
1009 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
1013 dummypkt
= (u32
*) (ofdm
? ofdmpkt
: cckpkt
);
1014 wlapi_bmac_write_template_ram(pi
->sh
->physhim
, 0, DUMMY_PKT_LEN
,
1017 bcma_write16(core
, D11REGOFFS(xmtsel
), 0);
1019 if (D11REV_GE(pi
->sh
->corerev
, 11))
1020 bcma_write16(core
, D11REGOFFS(wepctl
), 0x100);
1022 bcma_write16(core
, D11REGOFFS(wepctl
), 0);
1024 bcma_write16(core
, D11REGOFFS(txe_phyctl
),
1025 (ofdm
? 1 : 0) | PHY_TXC_ANT_0
);
1026 if (ISNPHY(pi
) || ISLCNPHY(pi
))
1027 bcma_write16(core
, D11REGOFFS(txe_phyctl1
), 0x1A02);
1029 bcma_write16(core
, D11REGOFFS(txe_wm_0
), 0);
1030 bcma_write16(core
, D11REGOFFS(txe_wm_1
), 0);
1032 bcma_write16(core
, D11REGOFFS(xmttplatetxptr
), 0);
1033 bcma_write16(core
, D11REGOFFS(xmttxcnt
), DUMMY_PKT_LEN
);
1035 bcma_write16(core
, D11REGOFFS(xmtsel
),
1036 ((8 << 8) | (1 << 5) | (1 << 2) | 2));
1038 bcma_write16(core
, D11REGOFFS(txe_ctl
), 0);
1042 wlc_phy_pa_override_nphy(pi
, OFF
);
1045 if (ISNPHY(pi
) || ISLCNPHY(pi
))
1046 bcma_write16(core
, D11REGOFFS(txe_aux
), 0xD0);
1048 bcma_write16(core
, D11REGOFFS(txe_aux
), ((1 << 5) | (1 << 4)));
1050 (void)bcma_read16(core
, D11REGOFFS(txe_aux
));
1053 count
= ofdm
? 30 : 250;
1054 while ((i
++ < count
)
1055 && (bcma_read16(core
, D11REGOFFS(txe_status
)) & (1 << 7)))
1060 while ((i
++ < 10) &&
1061 ((bcma_read16(core
, D11REGOFFS(txe_status
)) & (1 << 10)) == 0))
1066 while ((i
++ < 10) &&
1067 ((bcma_read16(core
, D11REGOFFS(ifsstat
)) & (1 << 8))))
1072 wlc_phy_pa_override_nphy(pi
, ON
);
1076 void wlc_phy_hold_upd(struct brcms_phy_pub
*pih
, u32 id
, bool set
)
1078 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1081 mboolset(pi
->measure_hold
, id
);
1083 mboolclr(pi
->measure_hold
, id
);
1088 void wlc_phy_mute_upd(struct brcms_phy_pub
*pih
, bool mute
, u32 flags
)
1090 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1093 mboolset(pi
->measure_hold
, PHY_HOLD_FOR_MUTE
);
1095 mboolclr(pi
->measure_hold
, PHY_HOLD_FOR_MUTE
);
1097 if (!mute
&& (flags
& PHY_MUTE_FOR_PREISM
))
1098 pi
->nphy_perical_last
= pi
->sh
->now
- pi
->sh
->glacial_timer
;
1102 void wlc_phy_clear_tssi(struct brcms_phy_pub
*pih
)
1104 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1109 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_B_TSSI_0
, NULL_TSSI_W
);
1110 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_B_TSSI_1
, NULL_TSSI_W
);
1111 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_G_TSSI_0
, NULL_TSSI_W
);
1112 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_G_TSSI_1
, NULL_TSSI_W
);
1116 static bool wlc_phy_cal_txpower_recalc_sw(struct brcms_phy
*pi
)
1121 void wlc_phy_switch_radio(struct brcms_phy_pub
*pih
, bool on
)
1123 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1124 (void)bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
));
1127 wlc_phy_switch_radio_nphy(pi
, on
);
1128 } else if (ISLCNPHY(pi
)) {
1130 and_phy_reg(pi
, 0x44c,
1133 (0x1 << 10) | (0x1 << 11) | (0x1 << 12)));
1134 and_phy_reg(pi
, 0x4b0, ~((0x1 << 3) | (0x1 << 11)));
1135 and_phy_reg(pi
, 0x4f9, ~(0x1 << 3));
1137 and_phy_reg(pi
, 0x44d,
1140 (0x1 << 12) | (0x1 << 13) | (0x1 << 14)));
1141 or_phy_reg(pi
, 0x44c,
1144 (0x1 << 10) | (0x1 << 11) | (0x1 << 12));
1146 and_phy_reg(pi
, 0x4b7, ~((0x7f << 8)));
1147 and_phy_reg(pi
, 0x4b1, ~((0x1 << 13)));
1148 or_phy_reg(pi
, 0x4b0, (0x1 << 3) | (0x1 << 11));
1149 and_phy_reg(pi
, 0x4fa, ~((0x1 << 3)));
1150 or_phy_reg(pi
, 0x4f9, (0x1 << 3));
1155 u16
wlc_phy_bw_state_get(struct brcms_phy_pub
*ppi
)
1157 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1162 void wlc_phy_bw_state_set(struct brcms_phy_pub
*ppi
, u16 bw
)
1164 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1169 void wlc_phy_chanspec_radio_set(struct brcms_phy_pub
*ppi
, u16 newch
)
1171 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1172 pi
->radio_chanspec
= newch
;
1176 u16
wlc_phy_chanspec_get(struct brcms_phy_pub
*ppi
)
1178 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1180 return pi
->radio_chanspec
;
1183 void wlc_phy_chanspec_set(struct brcms_phy_pub
*ppi
, u16 chanspec
)
1185 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1187 void (*chanspec_set
)(struct brcms_phy
*, u16
) = NULL
;
1188 m_cur_channel
= CHSPEC_CHANNEL(chanspec
);
1189 if (CHSPEC_IS5G(chanspec
))
1190 m_cur_channel
|= D11_CURCHANNEL_5G
;
1191 if (CHSPEC_IS40(chanspec
))
1192 m_cur_channel
|= D11_CURCHANNEL_40
;
1193 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_CURCHANNEL
, m_cur_channel
);
1195 chanspec_set
= pi
->pi_fptr
.chanset
;
1197 (*chanspec_set
)(pi
, chanspec
);
1201 int wlc_phy_chanspec_freq2bandrange_lpssn(uint freq
)
1206 range
= WL_CHAN_FREQ_RANGE_2G
;
1207 else if (freq
<= 5320)
1208 range
= WL_CHAN_FREQ_RANGE_5GL
;
1209 else if (freq
<= 5700)
1210 range
= WL_CHAN_FREQ_RANGE_5GM
;
1212 range
= WL_CHAN_FREQ_RANGE_5GH
;
1217 int wlc_phy_chanspec_bandrange_get(struct brcms_phy
*pi
, u16 chanspec
)
1220 uint channel
= CHSPEC_CHANNEL(chanspec
);
1221 uint freq
= wlc_phy_channel2freq(channel
);
1224 range
= wlc_phy_get_chan_freq_range_nphy(pi
, channel
);
1225 else if (ISLCNPHY(pi
))
1226 range
= wlc_phy_chanspec_freq2bandrange_lpssn(freq
);
1231 void wlc_phy_chanspec_ch14_widefilter_set(struct brcms_phy_pub
*ppi
,
1234 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1236 pi
->channel_14_wide_filter
= wide_filter
;
1240 int wlc_phy_channel2freq(uint channel
)
1244 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++)
1245 if (chan_info_all
[i
].chan
== channel
)
1246 return chan_info_all
[i
].freq
;
1251 wlc_phy_chanspec_band_validch(struct brcms_phy_pub
*ppi
, uint band
,
1252 struct brcms_chanvec
*channels
)
1254 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1258 memset(channels
, 0, sizeof(struct brcms_chanvec
));
1260 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1261 channel
= chan_info_all
[i
].chan
;
1263 if ((pi
->a_band_high_disable
) && (channel
>= FIRST_REF5_CHANNUM
)
1264 && (channel
<= LAST_REF5_CHANNUM
))
1267 if ((band
== BRCM_BAND_2G
&& channel
<= CH_MAX_2G_CHANNEL
) ||
1268 (band
== BRCM_BAND_5G
&& channel
> CH_MAX_2G_CHANNEL
))
1269 setbit(channels
->vec
, channel
);
1273 u16
wlc_phy_chanspec_band_firstch(struct brcms_phy_pub
*ppi
, uint band
)
1275 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1280 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1281 channel
= chan_info_all
[i
].chan
;
1283 if (ISNPHY(pi
) && pi
->bw
== WL_CHANSPEC_BW_40
) {
1286 for (j
= 0; j
< ARRAY_SIZE(chan_info_all
); j
++) {
1287 if (chan_info_all
[j
].chan
==
1288 channel
+ CH_10MHZ_APART
)
1292 if (j
== ARRAY_SIZE(chan_info_all
))
1295 channel
= upper_20_sb(channel
);
1296 chspec
= channel
| WL_CHANSPEC_BW_40
|
1297 WL_CHANSPEC_CTL_SB_LOWER
;
1298 if (band
== BRCM_BAND_2G
)
1299 chspec
|= WL_CHANSPEC_BAND_2G
;
1301 chspec
|= WL_CHANSPEC_BAND_5G
;
1303 chspec
= ch20mhz_chspec(channel
);
1305 if ((pi
->a_band_high_disable
) && (channel
>= FIRST_REF5_CHANNUM
)
1306 && (channel
<= LAST_REF5_CHANNUM
))
1309 if ((band
== BRCM_BAND_2G
&& channel
<= CH_MAX_2G_CHANNEL
) ||
1310 (band
== BRCM_BAND_5G
&& channel
> CH_MAX_2G_CHANNEL
))
1314 return (u16
) INVCHANSPEC
;
1317 int wlc_phy_txpower_get(struct brcms_phy_pub
*ppi
, uint
*qdbm
, bool *override
)
1319 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1321 *qdbm
= pi
->tx_user_target
[0];
1322 if (override
!= NULL
)
1323 *override
= pi
->txpwroverride
;
1327 void wlc_phy_txpower_target_set(struct brcms_phy_pub
*ppi
,
1328 struct txpwr_limits
*txpwr
)
1330 bool mac_enabled
= false;
1331 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1333 memcpy(&pi
->tx_user_target
[TXP_FIRST_CCK
],
1334 &txpwr
->cck
[0], BRCMS_NUM_RATES_CCK
);
1336 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM
],
1337 &txpwr
->ofdm
[0], BRCMS_NUM_RATES_OFDM
);
1338 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_20_CDD
],
1339 &txpwr
->ofdm_cdd
[0], BRCMS_NUM_RATES_OFDM
);
1341 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_40_SISO
],
1342 &txpwr
->ofdm_40_siso
[0], BRCMS_NUM_RATES_OFDM
);
1343 memcpy(&pi
->tx_user_target
[TXP_FIRST_OFDM_40_CDD
],
1344 &txpwr
->ofdm_40_cdd
[0], BRCMS_NUM_RATES_OFDM
);
1346 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_SISO
],
1347 &txpwr
->mcs_20_siso
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1348 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_CDD
],
1349 &txpwr
->mcs_20_cdd
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1350 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_STBC
],
1351 &txpwr
->mcs_20_stbc
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1352 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_20_SDM
],
1353 &txpwr
->mcs_20_mimo
[0], BRCMS_NUM_RATES_MCS_2_STREAM
);
1355 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_SISO
],
1356 &txpwr
->mcs_40_siso
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1357 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_CDD
],
1358 &txpwr
->mcs_40_cdd
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1359 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_STBC
],
1360 &txpwr
->mcs_40_stbc
[0], BRCMS_NUM_RATES_MCS_1_STREAM
);
1361 memcpy(&pi
->tx_user_target
[TXP_FIRST_MCS_40_SDM
],
1362 &txpwr
->mcs_40_mimo
[0], BRCMS_NUM_RATES_MCS_2_STREAM
);
1364 if (bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) & MCTL_EN_MAC
)
1368 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1370 wlc_phy_txpower_recalc_target(pi
);
1371 wlc_phy_cal_txpower_recalc_sw(pi
);
1374 wlapi_enable_mac(pi
->sh
->physhim
);
1377 int wlc_phy_txpower_set(struct brcms_phy_pub
*ppi
, uint qdbm
, bool override
)
1379 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1385 for (i
= 0; i
< TXP_NUM_RATES
; i
++)
1386 pi
->tx_user_target
[i
] = (u8
) qdbm
;
1388 pi
->txpwroverride
= false;
1391 if (!SCAN_INPROG_PHY(pi
)) {
1394 suspend
= (0 == (bcma_read32(pi
->d11core
,
1395 D11REGOFFS(maccontrol
)) &
1399 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1401 wlc_phy_txpower_recalc_target(pi
);
1402 wlc_phy_cal_txpower_recalc_sw(pi
);
1405 wlapi_enable_mac(pi
->sh
->physhim
);
1412 wlc_phy_txpower_sromlimit(struct brcms_phy_pub
*ppi
, uint channel
, u8
*min_pwr
,
1413 u8
*max_pwr
, int txp_rate_idx
)
1415 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1418 *min_pwr
= pi
->min_txpower
* BRCMS_TXPWR_DB_FACTOR
;
1421 if (txp_rate_idx
< 0)
1422 txp_rate_idx
= TXP_FIRST_CCK
;
1423 wlc_phy_txpower_sromlimit_get_nphy(pi
, channel
, max_pwr
,
1426 } else if ((channel
<= CH_MAX_2G_CHANNEL
)) {
1427 if (txp_rate_idx
< 0)
1428 txp_rate_idx
= TXP_FIRST_CCK
;
1429 *max_pwr
= pi
->tx_srom_max_rate_2g
[txp_rate_idx
];
1432 *max_pwr
= BRCMS_TXPWR_MAX
;
1434 if (txp_rate_idx
< 0)
1435 txp_rate_idx
= TXP_FIRST_OFDM
;
1437 for (i
= 0; i
< ARRAY_SIZE(chan_info_all
); i
++) {
1438 if (channel
== chan_info_all
[i
].chan
)
1443 *max_pwr
= pi
->hwtxpwr
[i
];
1446 if ((i
>= FIRST_MID_5G_CHAN
) && (i
<= LAST_MID_5G_CHAN
))
1448 pi
->tx_srom_max_rate_5g_mid
[txp_rate_idx
];
1449 if ((i
>= FIRST_HIGH_5G_CHAN
)
1450 && (i
<= LAST_HIGH_5G_CHAN
))
1452 pi
->tx_srom_max_rate_5g_hi
[txp_rate_idx
];
1453 if ((i
>= FIRST_LOW_5G_CHAN
) && (i
<= LAST_LOW_5G_CHAN
))
1455 pi
->tx_srom_max_rate_5g_low
[txp_rate_idx
];
1461 wlc_phy_txpower_sromlimit_max_get(struct brcms_phy_pub
*ppi
, uint chan
,
1462 u8
*max_txpwr
, u8
*min_txpwr
)
1464 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1466 u8 tx_pwr_min
= 255;
1468 u8 maxtxpwr
, mintxpwr
, rate
, pactrl
;
1472 max_num_rate
= ISNPHY(pi
) ? TXP_NUM_RATES
:
1473 ISLCNPHY(pi
) ? (TXP_LAST_SISO_MCS_20
+
1474 1) : (TXP_LAST_OFDM
+ 1);
1476 for (rate
= 0; rate
< max_num_rate
; rate
++) {
1478 wlc_phy_txpower_sromlimit(ppi
, chan
, &mintxpwr
, &maxtxpwr
,
1481 maxtxpwr
= (maxtxpwr
> pactrl
) ? (maxtxpwr
- pactrl
) : 0;
1483 maxtxpwr
= (maxtxpwr
> 6) ? (maxtxpwr
- 6) : 0;
1485 tx_pwr_max
= max(tx_pwr_max
, maxtxpwr
);
1486 tx_pwr_min
= min(tx_pwr_min
, maxtxpwr
);
1488 *max_txpwr
= tx_pwr_max
;
1489 *min_txpwr
= tx_pwr_min
;
1493 wlc_phy_txpower_boardlimit_band(struct brcms_phy_pub
*ppi
, uint bandunit
,
1494 s32
*max_pwr
, s32
*min_pwr
, u32
*step_pwr
)
1499 u8
wlc_phy_txpower_get_target_min(struct brcms_phy_pub
*ppi
)
1501 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1503 return pi
->tx_power_min
;
1506 u8
wlc_phy_txpower_get_target_max(struct brcms_phy_pub
*ppi
)
1508 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1510 return pi
->tx_power_max
;
1513 static s8
wlc_phy_env_measure_vbat(struct brcms_phy
*pi
)
1516 return wlc_lcnphy_vbatsense(pi
, 0);
1521 static s8
wlc_phy_env_measure_temperature(struct brcms_phy
*pi
)
1524 return wlc_lcnphy_tempsense_degree(pi
, 0);
1529 static void wlc_phy_upd_env_txpwr_rate_limits(struct brcms_phy
*pi
, u32 band
)
1534 for (i
= 0; i
< TXP_NUM_RATES
; i
++)
1535 pi
->txpwr_env_limit
[i
] = BRCMS_TXPWR_MAX
;
1537 vbat
= wlc_phy_env_measure_vbat(pi
);
1538 temp
= wlc_phy_env_measure_temperature(pi
);
1543 wlc_user_txpwr_antport_to_rfport(struct brcms_phy
*pi
, uint chan
, u32 band
,
1548 if (!pi
->user_txpwr_at_rfport
)
1553 void wlc_phy_txpower_recalc_target(struct brcms_phy
*pi
)
1555 u8 maxtxpwr
, mintxpwr
, rate
, pactrl
;
1557 u8 tx_pwr_target
[TXP_NUM_RATES
];
1559 u8 tx_pwr_min
= 255;
1560 u8 tx_pwr_max_rate_ind
= 0;
1564 u32 band
= CHSPEC2BAND(pi
->radio_chanspec
);
1565 void (*txpwr_recalc_fn
)(struct brcms_phy
*) = NULL
;
1567 chspec
= pi
->radio_chanspec
;
1568 if (CHSPEC_CTL_SB(chspec
) == WL_CHANSPEC_CTL_SB_NONE
)
1569 target_chan
= CHSPEC_CHANNEL(chspec
);
1570 else if (CHSPEC_CTL_SB(chspec
) == WL_CHANSPEC_CTL_SB_UPPER
)
1571 target_chan
= upper_20_sb(CHSPEC_CHANNEL(chspec
));
1573 target_chan
= lower_20_sb(CHSPEC_CHANNEL(chspec
));
1579 if (CHSPEC_IS40(pi
->radio_chanspec
)) {
1580 offset_mcs
= pi
->mcs40_po
;
1581 for (i
= TXP_FIRST_SISO_MCS_20
;
1582 i
<= TXP_LAST_SISO_MCS_20
; i
++) {
1583 pi
->tx_srom_max_rate_2g
[i
- 8] =
1584 pi
->tx_srom_max_2g
-
1585 ((offset_mcs
& 0xf) * 2);
1589 offset_mcs
= pi
->mcs20_po
;
1590 for (i
= TXP_FIRST_SISO_MCS_20
;
1591 i
<= TXP_LAST_SISO_MCS_20
; i
++) {
1592 pi
->tx_srom_max_rate_2g
[i
- 8] =
1593 pi
->tx_srom_max_2g
-
1594 ((offset_mcs
& 0xf) * 2);
1600 max_num_rate
= ((ISNPHY(pi
)) ? (TXP_NUM_RATES
) :
1602 (TXP_LAST_SISO_MCS_20
+ 1) : (TXP_LAST_OFDM
+ 1)));
1604 wlc_phy_upd_env_txpwr_rate_limits(pi
, band
);
1606 for (rate
= start_rate
; rate
< max_num_rate
; rate
++) {
1608 tx_pwr_target
[rate
] = pi
->tx_user_target
[rate
];
1610 if (pi
->user_txpwr_at_rfport
)
1611 tx_pwr_target
[rate
] +=
1612 wlc_user_txpwr_antport_to_rfport(pi
,
1617 wlc_phy_txpower_sromlimit((struct brcms_phy_pub
*) pi
,
1619 &mintxpwr
, &maxtxpwr
, rate
);
1621 maxtxpwr
= min(maxtxpwr
, pi
->txpwr_limit
[rate
]);
1623 maxtxpwr
= (maxtxpwr
> pactrl
) ? (maxtxpwr
- pactrl
) : 0;
1625 maxtxpwr
= (maxtxpwr
> 6) ? (maxtxpwr
- 6) : 0;
1627 maxtxpwr
= min(maxtxpwr
, tx_pwr_target
[rate
]);
1629 if (pi
->txpwr_percent
<= 100)
1630 maxtxpwr
= (maxtxpwr
* pi
->txpwr_percent
) / 100;
1632 tx_pwr_target
[rate
] = max(maxtxpwr
, mintxpwr
);
1634 tx_pwr_target
[rate
] =
1635 min(tx_pwr_target
[rate
], pi
->txpwr_env_limit
[rate
]);
1637 if (tx_pwr_target
[rate
] > tx_pwr_max
)
1638 tx_pwr_max_rate_ind
= rate
;
1640 tx_pwr_max
= max(tx_pwr_max
, tx_pwr_target
[rate
]);
1641 tx_pwr_min
= min(tx_pwr_min
, tx_pwr_target
[rate
]);
1644 memset(pi
->tx_power_offset
, 0, sizeof(pi
->tx_power_offset
));
1645 pi
->tx_power_max
= tx_pwr_max
;
1646 pi
->tx_power_min
= tx_pwr_min
;
1647 pi
->tx_power_max_rate_ind
= tx_pwr_max_rate_ind
;
1648 for (rate
= 0; rate
< max_num_rate
; rate
++) {
1650 pi
->tx_power_target
[rate
] = tx_pwr_target
[rate
];
1652 if (!pi
->hwpwrctrl
|| ISNPHY(pi
))
1653 pi
->tx_power_offset
[rate
] =
1654 pi
->tx_power_max
- pi
->tx_power_target
[rate
];
1656 pi
->tx_power_offset
[rate
] =
1657 pi
->tx_power_target
[rate
] - pi
->tx_power_min
;
1660 txpwr_recalc_fn
= pi
->pi_fptr
.txpwrrecalc
;
1661 if (txpwr_recalc_fn
)
1662 (*txpwr_recalc_fn
)(pi
);
1666 wlc_phy_txpower_reg_limit_calc(struct brcms_phy
*pi
, struct txpwr_limits
*txpwr
,
1669 u8 tmp_txpwr_limit
[2 * BRCMS_NUM_RATES_OFDM
];
1670 u8
*txpwr_ptr1
= NULL
, *txpwr_ptr2
= NULL
;
1671 int rate_start_index
= 0, rate1
, rate2
, k
;
1673 for (rate1
= WL_TX_POWER_CCK_FIRST
, rate2
= 0;
1674 rate2
< WL_TX_POWER_CCK_NUM
; rate1
++, rate2
++)
1675 pi
->txpwr_limit
[rate1
] = txpwr
->cck
[rate2
];
1677 for (rate1
= WL_TX_POWER_OFDM_FIRST
, rate2
= 0;
1678 rate2
< WL_TX_POWER_OFDM_NUM
; rate1
++, rate2
++)
1679 pi
->txpwr_limit
[rate1
] = txpwr
->ofdm
[rate2
];
1683 for (k
= 0; k
< 4; k
++) {
1687 txpwr_ptr1
= txpwr
->mcs_20_siso
;
1688 txpwr_ptr2
= txpwr
->ofdm
;
1689 rate_start_index
= WL_TX_POWER_OFDM_FIRST
;
1693 txpwr_ptr1
= txpwr
->mcs_20_cdd
;
1694 txpwr_ptr2
= txpwr
->ofdm_cdd
;
1695 rate_start_index
= WL_TX_POWER_OFDM20_CDD_FIRST
;
1699 txpwr_ptr1
= txpwr
->mcs_40_siso
;
1700 txpwr_ptr2
= txpwr
->ofdm_40_siso
;
1702 WL_TX_POWER_OFDM40_SISO_FIRST
;
1706 txpwr_ptr1
= txpwr
->mcs_40_cdd
;
1707 txpwr_ptr2
= txpwr
->ofdm_40_cdd
;
1708 rate_start_index
= WL_TX_POWER_OFDM40_CDD_FIRST
;
1712 for (rate2
= 0; rate2
< BRCMS_NUM_RATES_OFDM
;
1714 tmp_txpwr_limit
[rate2
] = 0;
1715 tmp_txpwr_limit
[BRCMS_NUM_RATES_OFDM
+ rate2
] =
1718 wlc_phy_mcs_to_ofdm_powers_nphy(
1720 BRCMS_NUM_RATES_OFDM
-
1721 1, BRCMS_NUM_RATES_OFDM
);
1722 for (rate1
= rate_start_index
, rate2
= 0;
1723 rate2
< BRCMS_NUM_RATES_OFDM
; rate1
++, rate2
++)
1724 pi
->txpwr_limit
[rate1
] =
1725 min(txpwr_ptr2
[rate2
],
1726 tmp_txpwr_limit
[rate2
]);
1729 for (k
= 0; k
< 4; k
++) {
1733 txpwr_ptr1
= txpwr
->ofdm
;
1734 txpwr_ptr2
= txpwr
->mcs_20_siso
;
1735 rate_start_index
= WL_TX_POWER_MCS20_SISO_FIRST
;
1739 txpwr_ptr1
= txpwr
->ofdm_cdd
;
1740 txpwr_ptr2
= txpwr
->mcs_20_cdd
;
1741 rate_start_index
= WL_TX_POWER_MCS20_CDD_FIRST
;
1745 txpwr_ptr1
= txpwr
->ofdm_40_siso
;
1746 txpwr_ptr2
= txpwr
->mcs_40_siso
;
1747 rate_start_index
= WL_TX_POWER_MCS40_SISO_FIRST
;
1751 txpwr_ptr1
= txpwr
->ofdm_40_cdd
;
1752 txpwr_ptr2
= txpwr
->mcs_40_cdd
;
1753 rate_start_index
= WL_TX_POWER_MCS40_CDD_FIRST
;
1756 for (rate2
= 0; rate2
< BRCMS_NUM_RATES_OFDM
;
1758 tmp_txpwr_limit
[rate2
] = 0;
1759 tmp_txpwr_limit
[BRCMS_NUM_RATES_OFDM
+ rate2
] =
1762 wlc_phy_ofdm_to_mcs_powers_nphy(
1764 BRCMS_NUM_RATES_OFDM
-
1765 1, BRCMS_NUM_RATES_OFDM
);
1766 for (rate1
= rate_start_index
, rate2
= 0;
1767 rate2
< BRCMS_NUM_RATES_MCS_1_STREAM
;
1769 pi
->txpwr_limit
[rate1
] =
1770 min(txpwr_ptr2
[rate2
],
1771 tmp_txpwr_limit
[rate2
]);
1774 for (k
= 0; k
< 2; k
++) {
1778 rate_start_index
= WL_TX_POWER_MCS20_STBC_FIRST
;
1779 txpwr_ptr1
= txpwr
->mcs_20_stbc
;
1783 rate_start_index
= WL_TX_POWER_MCS40_STBC_FIRST
;
1784 txpwr_ptr1
= txpwr
->mcs_40_stbc
;
1787 for (rate1
= rate_start_index
, rate2
= 0;
1788 rate2
< BRCMS_NUM_RATES_MCS_1_STREAM
;
1790 pi
->txpwr_limit
[rate1
] = txpwr_ptr1
[rate2
];
1793 for (k
= 0; k
< 2; k
++) {
1797 rate_start_index
= WL_TX_POWER_MCS20_SDM_FIRST
;
1798 txpwr_ptr1
= txpwr
->mcs_20_mimo
;
1802 rate_start_index
= WL_TX_POWER_MCS40_SDM_FIRST
;
1803 txpwr_ptr1
= txpwr
->mcs_40_mimo
;
1806 for (rate1
= rate_start_index
, rate2
= 0;
1807 rate2
< BRCMS_NUM_RATES_MCS_2_STREAM
;
1809 pi
->txpwr_limit
[rate1
] = txpwr_ptr1
[rate2
];
1812 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
] = txpwr
->mcs32
;
1814 pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
] =
1815 min(pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
],
1816 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
]);
1817 pi
->txpwr_limit
[WL_TX_POWER_MCS_32
] =
1818 pi
->txpwr_limit
[WL_TX_POWER_MCS40_CDD_FIRST
];
1822 void wlc_phy_txpwr_percent_set(struct brcms_phy_pub
*ppi
, u8 txpwr_percent
)
1824 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1826 pi
->txpwr_percent
= txpwr_percent
;
1829 void wlc_phy_machwcap_set(struct brcms_phy_pub
*ppi
, u32 machwcap
)
1831 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1833 pi
->sh
->machwcap
= machwcap
;
1836 void wlc_phy_runbist_config(struct brcms_phy_pub
*ppi
, bool start_end
)
1838 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1842 if (start_end
== ON
) {
1846 if (NREV_IS(pi
->pubpi
.phy_rev
, 3)
1847 || NREV_IS(pi
->pubpi
.phy_rev
, 4)) {
1848 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
),
1850 bcma_set16(pi
->d11core
, D11REGOFFS(phyregdata
),
1854 if (NREV_IS(pi
->pubpi
.phy_rev
, 3)
1855 || NREV_IS(pi
->pubpi
.phy_rev
, 4)) {
1856 bcma_wflush16(pi
->d11core
, D11REGOFFS(phyregaddr
),
1858 bcma_write16(pi
->d11core
, D11REGOFFS(phyregdata
), rxc
);
1861 wlc_phy_por_inform(ppi
);
1866 wlc_phy_txpower_limit_set(struct brcms_phy_pub
*ppi
, struct txpwr_limits
*txpwr
,
1869 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1871 wlc_phy_txpower_reg_limit_calc(pi
, txpwr
, chanspec
);
1875 for (i
= TXP_FIRST_OFDM_20_CDD
, j
= 0;
1876 j
< BRCMS_NUM_RATES_MCS_1_STREAM
; i
++, j
++) {
1877 if (txpwr
->mcs_20_siso
[j
])
1878 pi
->txpwr_limit
[i
] = txpwr
->mcs_20_siso
[j
];
1880 pi
->txpwr_limit
[i
] = txpwr
->ofdm
[j
];
1884 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1886 wlc_phy_txpower_recalc_target(pi
);
1887 wlc_phy_cal_txpower_recalc_sw(pi
);
1888 wlapi_enable_mac(pi
->sh
->physhim
);
1891 void wlc_phy_ofdm_rateset_war(struct brcms_phy_pub
*pih
, bool war
)
1893 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1895 pi
->ofdm_rateset_war
= war
;
1898 void wlc_phy_bf_preempt_enable(struct brcms_phy_pub
*pih
, bool bf_preempt
)
1900 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
1902 pi
->bf_preempt_4306
= bf_preempt
;
1905 void wlc_phy_txpower_update_shm(struct brcms_phy
*pi
)
1914 if (pi
->hwpwrctrl
) {
1917 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_MAX
, 63);
1918 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_N
,
1919 1 << NUM_TSSI_FRAMES
);
1921 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_TARGET
,
1922 pi
->tx_power_min
<< NUM_TSSI_FRAMES
);
1924 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_TXPWR_CUR
,
1927 for (j
= TXP_FIRST_OFDM
; j
<= TXP_LAST_OFDM
; j
++) {
1928 const u8 ucode_ofdm_rates
[] = {
1929 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c
1931 offset
= wlapi_bmac_rate_shm_offset(
1933 ucode_ofdm_rates
[j
- TXP_FIRST_OFDM
]);
1934 wlapi_bmac_write_shm(pi
->sh
->physhim
, offset
+ 6,
1935 pi
->tx_power_offset
[j
]);
1936 wlapi_bmac_write_shm(pi
->sh
->physhim
, offset
+ 14,
1937 -(pi
->tx_power_offset
[j
] / 2));
1940 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF2
, MHF2_HWPWRCTL
,
1941 MHF2_HWPWRCTL
, BRCM_BAND_ALL
);
1945 for (i
= TXP_FIRST_OFDM
; i
<= TXP_LAST_OFDM
; i
++)
1946 pi
->tx_power_offset
[i
] =
1947 (u8
) roundup(pi
->tx_power_offset
[i
], 8);
1948 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_OFDM_OFFSET
,
1950 ((pi
->tx_power_offset
[TXP_FIRST_OFDM
]
1955 bool wlc_phy_txpower_hw_ctrl_get(struct brcms_phy_pub
*ppi
)
1957 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1960 return pi
->nphy_txpwrctrl
;
1962 return pi
->hwpwrctrl
;
1965 void wlc_phy_txpower_hw_ctrl_set(struct brcms_phy_pub
*ppi
, bool hwpwrctrl
)
1967 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
1970 if (!pi
->hwpwrctrl_capable
)
1973 pi
->hwpwrctrl
= hwpwrctrl
;
1974 pi
->nphy_txpwrctrl
= hwpwrctrl
;
1975 pi
->txpwrctrl
= hwpwrctrl
;
1978 suspend
= (0 == (bcma_read32(pi
->d11core
,
1979 D11REGOFFS(maccontrol
)) &
1982 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
1984 wlc_phy_txpwrctrl_enable_nphy(pi
, pi
->nphy_txpwrctrl
);
1985 if (pi
->nphy_txpwrctrl
== PHY_TPC_HW_OFF
)
1986 wlc_phy_txpwr_fixpower_nphy(pi
);
1988 mod_phy_reg(pi
, 0x1e7, (0x7f << 0),
1989 pi
->saved_txpwr_idx
);
1992 wlapi_enable_mac(pi
->sh
->physhim
);
1996 void wlc_phy_txpower_ipa_upd(struct brcms_phy
*pi
)
1999 if (NREV_GE(pi
->pubpi
.phy_rev
, 3)) {
2000 pi
->ipa2g_on
= (pi
->srom_fem2g
.extpagain
== 2);
2001 pi
->ipa5g_on
= (pi
->srom_fem5g
.extpagain
== 2);
2003 pi
->ipa2g_on
= false;
2004 pi
->ipa5g_on
= false;
2008 static u32
wlc_phy_txpower_est_power_nphy(struct brcms_phy
*pi
)
2010 s16 tx0_status
, tx1_status
;
2011 u16 estPower1
, estPower2
;
2012 u8 pwr0
, pwr1
, adj_pwr0
, adj_pwr1
;
2015 estPower1
= read_phy_reg(pi
, 0x118);
2016 estPower2
= read_phy_reg(pi
, 0x119);
2018 if ((estPower1
& (0x1 << 8)) == (0x1 << 8))
2019 pwr0
= (u8
) (estPower1
& (0xff << 0)) >> 0;
2023 if ((estPower2
& (0x1 << 8)) == (0x1 << 8))
2024 pwr1
= (u8
) (estPower2
& (0xff << 0)) >> 0;
2028 tx0_status
= read_phy_reg(pi
, 0x1ed);
2029 tx1_status
= read_phy_reg(pi
, 0x1ee);
2031 if ((tx0_status
& (0x1 << 15)) == (0x1 << 15))
2032 adj_pwr0
= (u8
) (tx0_status
& (0xff << 0)) >> 0;
2035 if ((tx1_status
& (0x1 << 15)) == (0x1 << 15))
2036 adj_pwr1
= (u8
) (tx1_status
& (0xff << 0)) >> 0;
2040 est_pwr
= (u32
) ((pwr0
<< 24) | (pwr1
<< 16) | (adj_pwr0
<< 8) |
2047 wlc_phy_txpower_get_current(struct brcms_phy_pub
*ppi
, struct tx_power
*power
,
2050 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2051 uint rate
, num_rates
;
2052 u8 min_pwr
, max_pwr
;
2054 #if WL_TX_POWER_RATES != TXP_NUM_RATES
2055 #error "struct tx_power out of sync with this fn"
2059 power
->rf_cores
= 2;
2060 power
->flags
|= (WL_TX_POWER_F_MIMO
);
2061 if (pi
->nphy_txpwrctrl
== PHY_TPC_HW_ON
)
2063 (WL_TX_POWER_F_ENABLED
| WL_TX_POWER_F_HW
);
2064 } else if (ISLCNPHY(pi
)) {
2065 power
->rf_cores
= 1;
2066 power
->flags
|= (WL_TX_POWER_F_SISO
);
2067 if (pi
->radiopwr_override
== RADIOPWR_OVERRIDE_DEF
)
2068 power
->flags
|= WL_TX_POWER_F_ENABLED
;
2070 power
->flags
|= WL_TX_POWER_F_HW
;
2073 num_rates
= ((ISNPHY(pi
)) ? (TXP_NUM_RATES
) :
2075 (TXP_LAST_OFDM_20_CDD
+ 1) : (TXP_LAST_OFDM
+ 1)));
2077 for (rate
= 0; rate
< num_rates
; rate
++) {
2078 power
->user_limit
[rate
] = pi
->tx_user_target
[rate
];
2079 wlc_phy_txpower_sromlimit(ppi
, channel
, &min_pwr
, &max_pwr
,
2081 power
->board_limit
[rate
] = (u8
) max_pwr
;
2082 power
->target
[rate
] = pi
->tx_power_target
[rate
];
2088 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2089 wlc_phyreg_enter((struct brcms_phy_pub
*) pi
);
2090 est_pout
= wlc_phy_txpower_est_power_nphy(pi
);
2091 wlc_phyreg_exit((struct brcms_phy_pub
*) pi
);
2092 wlapi_enable_mac(pi
->sh
->physhim
);
2094 power
->est_Pout
[0] = (est_pout
>> 8) & 0xff;
2095 power
->est_Pout
[1] = est_pout
& 0xff;
2097 power
->est_Pout_act
[0] = est_pout
>> 24;
2098 power
->est_Pout_act
[1] = (est_pout
>> 16) & 0xff;
2100 if (power
->est_Pout
[0] == 0x80)
2101 power
->est_Pout
[0] = 0;
2102 if (power
->est_Pout
[1] == 0x80)
2103 power
->est_Pout
[1] = 0;
2105 if (power
->est_Pout_act
[0] == 0x80)
2106 power
->est_Pout_act
[0] = 0;
2107 if (power
->est_Pout_act
[1] == 0x80)
2108 power
->est_Pout_act
[1] = 0;
2110 power
->est_Pout_cck
= 0;
2112 power
->tx_power_max
[0] = pi
->tx_power_max
;
2113 power
->tx_power_max
[1] = pi
->tx_power_max
;
2115 power
->tx_power_max_rate_ind
[0] = pi
->tx_power_max_rate_ind
;
2116 power
->tx_power_max_rate_ind
[1] = pi
->tx_power_max_rate_ind
;
2117 } else if (pi
->hwpwrctrl
&& pi
->sh
->up
) {
2119 wlc_phyreg_enter(ppi
);
2122 power
->tx_power_max
[0] = pi
->tx_power_max
;
2123 power
->tx_power_max
[1] = pi
->tx_power_max
;
2125 power
->tx_power_max_rate_ind
[0] =
2126 pi
->tx_power_max_rate_ind
;
2127 power
->tx_power_max_rate_ind
[1] =
2128 pi
->tx_power_max_rate_ind
;
2130 if (wlc_phy_tpc_isenabled_lcnphy(pi
))
2133 WL_TX_POWER_F_ENABLED
);
2136 ~(WL_TX_POWER_F_HW
|
2137 WL_TX_POWER_F_ENABLED
);
2139 wlc_lcnphy_get_tssi(pi
, (s8
*) &power
->est_Pout
[0],
2140 (s8
*) &power
->est_Pout_cck
);
2142 wlc_phyreg_exit(ppi
);
2146 void wlc_phy_antsel_type_set(struct brcms_phy_pub
*ppi
, u8 antsel_type
)
2148 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2150 pi
->antsel_type
= antsel_type
;
2153 bool wlc_phy_test_ison(struct brcms_phy_pub
*ppi
)
2155 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2157 return pi
->phytest_on
;
2160 void wlc_phy_ant_rxdiv_set(struct brcms_phy_pub
*ppi
, u8 val
)
2162 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2165 pi
->sh
->rx_antdiv
= val
;
2167 if (!(ISNPHY(pi
) && D11REV_IS(pi
->sh
->corerev
, 16))) {
2168 if (val
> ANT_RX_DIV_FORCE_1
)
2169 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF1
, MHF1_ANTDIV
,
2170 MHF1_ANTDIV
, BRCM_BAND_ALL
);
2172 wlapi_bmac_mhf(pi
->sh
->physhim
, MHF1
, MHF1_ANTDIV
, 0,
2182 suspend
= (0 == (bcma_read32(pi
->d11core
, D11REGOFFS(maccontrol
)) &
2185 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2188 if (val
> ANT_RX_DIV_FORCE_1
) {
2189 mod_phy_reg(pi
, 0x410, (0x1 << 1), 0x01 << 1);
2190 mod_phy_reg(pi
, 0x410,
2192 ((ANT_RX_DIV_START_1
== val
) ? 1 : 0) << 0);
2194 mod_phy_reg(pi
, 0x410, (0x1 << 1), 0x00 << 1);
2195 mod_phy_reg(pi
, 0x410, (0x1 << 0), (u16
) val
<< 0);
2200 wlapi_enable_mac(pi
->sh
->physhim
);
2206 wlc_phy_noise_calc_phy(struct brcms_phy
*pi
, u32
*cmplx_pwr
, s8
*pwr_ant
)
2208 s8 cmplx_pwr_dbm
[PHY_CORE_MAX
];
2211 memset((u8
*) cmplx_pwr_dbm
, 0, sizeof(cmplx_pwr_dbm
));
2212 wlc_phy_compute_dB(cmplx_pwr
, cmplx_pwr_dbm
, pi
->pubpi
.phy_corenum
);
2214 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2215 if (NREV_GE(pi
->pubpi
.phy_rev
, 3))
2216 cmplx_pwr_dbm
[i
] += (s8
) PHY_NOISE_OFFSETFACT_4322
;
2219 cmplx_pwr_dbm
[i
] += (s8
) (16 - (15) * 3 - 70);
2222 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2223 pi
->nphy_noise_win
[i
][pi
->nphy_noise_index
] = cmplx_pwr_dbm
[i
];
2224 pwr_ant
[i
] = cmplx_pwr_dbm
[i
];
2226 pi
->nphy_noise_index
=
2227 MODINC_POW2(pi
->nphy_noise_index
, PHY_NOISE_WINDOW_SZ
);
2231 static void wlc_phy_noise_cb(struct brcms_phy
*pi
, u8 channel
, s8 noise_dbm
)
2233 if (!pi
->phynoise_state
)
2236 if (pi
->phynoise_state
& PHY_NOISE_STATE_MON
) {
2237 if (pi
->phynoise_chan_watchdog
== channel
) {
2238 pi
->sh
->phy_noise_window
[pi
->sh
->phy_noise_index
] =
2240 pi
->sh
->phy_noise_index
=
2241 MODINC(pi
->sh
->phy_noise_index
, MA_WINDOW_SZ
);
2243 pi
->phynoise_state
&= ~PHY_NOISE_STATE_MON
;
2246 if (pi
->phynoise_state
& PHY_NOISE_STATE_EXTERNAL
)
2247 pi
->phynoise_state
&= ~PHY_NOISE_STATE_EXTERNAL
;
2251 static s8
wlc_phy_noise_read_shmem(struct brcms_phy
*pi
)
2253 u32 cmplx_pwr
[PHY_CORE_MAX
];
2254 s8 noise_dbm_ant
[PHY_CORE_MAX
];
2256 u32 cmplx_pwr_tot
= 0;
2257 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2260 memset((u8
*) cmplx_pwr
, 0, sizeof(cmplx_pwr
));
2261 memset((u8
*) noise_dbm_ant
, 0, sizeof(noise_dbm_ant
));
2263 for (idx
= 0, core
= 0; core
< pi
->pubpi
.phy_corenum
; idx
+= 2,
2265 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP(idx
));
2266 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
,
2267 M_PWRIND_MAP(idx
+ 1));
2268 cmplx_pwr
[core
] = (hi
<< 16) + lo
;
2269 cmplx_pwr_tot
+= cmplx_pwr
[core
];
2270 if (cmplx_pwr
[core
] == 0)
2271 noise_dbm_ant
[core
] = PHY_NOISE_FIXED_VAL_NPHY
;
2273 cmplx_pwr
[core
] >>= PHY_NOISE_SAMPLE_LOG_NUM_UCODE
;
2276 if (cmplx_pwr_tot
!= 0)
2277 wlc_phy_noise_calc_phy(pi
, cmplx_pwr
, noise_dbm_ant
);
2279 for (core
= 0; core
< pi
->pubpi
.phy_corenum
; core
++) {
2280 pi
->nphy_noise_win
[core
][pi
->nphy_noise_index
] =
2281 noise_dbm_ant
[core
];
2283 if (noise_dbm_ant
[core
] > noise_dbm
)
2284 noise_dbm
= noise_dbm_ant
[core
];
2286 pi
->nphy_noise_index
=
2287 MODINC_POW2(pi
->nphy_noise_index
, PHY_NOISE_WINDOW_SZ
);
2293 void wlc_phy_noise_sample_intr(struct brcms_phy_pub
*pih
)
2295 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2298 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2301 u32 cmplx_pwr
, cmplx_pwr0
, cmplx_pwr1
;
2303 s32 pwr_offset_dB
, gain_dB
;
2304 u16 status_0
, status_1
;
2306 jssi_aux
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_AUX
);
2307 channel
= jssi_aux
& D11_CURCHANNEL_MAX
;
2309 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
);
2310 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
);
2311 cmplx_pwr0
= (hi
<< 16) + lo
;
2313 lo
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
);
2314 hi
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
);
2315 cmplx_pwr1
= (hi
<< 16) + lo
;
2316 cmplx_pwr
= (cmplx_pwr0
+ cmplx_pwr1
) >> 6;
2319 status_1
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_0
);
2320 if ((cmplx_pwr
> 0 && cmplx_pwr
< 500)
2321 && ((status_1
& 0xc000) == 0x4000)) {
2323 wlc_phy_compute_dB(&cmplx_pwr
, &noise_dbm
,
2324 pi
->pubpi
.phy_corenum
);
2325 pwr_offset_dB
= (read_phy_reg(pi
, 0x434) & 0xFF);
2326 if (pwr_offset_dB
> 127)
2327 pwr_offset_dB
-= 256;
2329 noise_dbm
+= (s8
) (pwr_offset_dB
- 30);
2331 gain_dB
= (status_0
& 0x1ff);
2332 noise_dbm
-= (s8
) (gain_dB
);
2334 noise_dbm
= PHY_NOISE_FIXED_VAL_LCNPHY
;
2336 } else if (ISNPHY(pi
)) {
2338 jssi_aux
= wlapi_bmac_read_shm(pi
->sh
->physhim
, M_JSSI_AUX
);
2339 channel
= jssi_aux
& D11_CURCHANNEL_MAX
;
2341 noise_dbm
= wlc_phy_noise_read_shmem(pi
);
2344 wlc_phy_noise_cb(pi
, channel
, noise_dbm
);
2349 wlc_phy_noise_sample_request(struct brcms_phy_pub
*pih
, u8 reason
, u8 ch
)
2351 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2352 s8 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2353 bool sampling_in_progress
= (pi
->phynoise_state
!= 0);
2354 bool wait_for_intr
= true;
2357 case PHY_NOISE_SAMPLE_MON
:
2358 pi
->phynoise_chan_watchdog
= ch
;
2359 pi
->phynoise_state
|= PHY_NOISE_STATE_MON
;
2362 case PHY_NOISE_SAMPLE_EXTERNAL
:
2363 pi
->phynoise_state
|= PHY_NOISE_STATE_EXTERNAL
;
2370 if (sampling_in_progress
)
2373 pi
->phynoise_now
= pi
->sh
->now
;
2375 if (pi
->phy_fixed_noise
) {
2377 pi
->nphy_noise_win
[WL_ANT_IDX_1
][pi
->nphy_noise_index
] =
2378 PHY_NOISE_FIXED_VAL_NPHY
;
2379 pi
->nphy_noise_win
[WL_ANT_IDX_2
][pi
->nphy_noise_index
] =
2380 PHY_NOISE_FIXED_VAL_NPHY
;
2381 pi
->nphy_noise_index
= MODINC_POW2(pi
->nphy_noise_index
,
2382 PHY_NOISE_WINDOW_SZ
);
2383 noise_dbm
= PHY_NOISE_FIXED_VAL_NPHY
;
2385 noise_dbm
= PHY_NOISE_FIXED_VAL
;
2388 wait_for_intr
= false;
2393 if (!pi
->phynoise_polling
2394 || (reason
== PHY_NOISE_SAMPLE_EXTERNAL
)) {
2395 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_JSSI_0
, 0);
2396 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
, 0);
2397 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
, 0);
2398 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
, 0);
2399 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
, 0);
2401 bcma_set32(pi
->d11core
, D11REGOFFS(maccommand
),
2404 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2405 wlc_lcnphy_deaf_mode(pi
, (bool) 0);
2406 noise_dbm
= (s8
) wlc_lcnphy_rx_signal_power(pi
, 20);
2407 wlc_lcnphy_deaf_mode(pi
, (bool) 1);
2408 wlapi_enable_mac(pi
->sh
->physhim
);
2409 wait_for_intr
= false;
2411 } else if (ISNPHY(pi
)) {
2412 if (!pi
->phynoise_polling
2413 || (reason
== PHY_NOISE_SAMPLE_EXTERNAL
)) {
2415 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP0
, 0);
2416 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP1
, 0);
2417 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP2
, 0);
2418 wlapi_bmac_write_shm(pi
->sh
->physhim
, M_PWRIND_MAP3
, 0);
2420 bcma_set32(pi
->d11core
, D11REGOFFS(maccommand
),
2423 struct phy_iq_est est
[PHY_CORE_MAX
];
2424 u32 cmplx_pwr
[PHY_CORE_MAX
];
2425 s8 noise_dbm_ant
[PHY_CORE_MAX
];
2426 u16 log_num_samps
, num_samps
, classif_state
= 0;
2431 memset((u8
*) est
, 0, sizeof(est
));
2432 memset((u8
*) cmplx_pwr
, 0, sizeof(cmplx_pwr
));
2433 memset((u8
*) noise_dbm_ant
, 0, sizeof(noise_dbm_ant
));
2435 log_num_samps
= PHY_NOISE_SAMPLE_LOG_NUM_NPHY
;
2436 num_samps
= 1 << log_num_samps
;
2438 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2439 classif_state
= wlc_phy_classifier_nphy(pi
, 0, 0);
2440 wlc_phy_classifier_nphy(pi
, 3, 0);
2441 wlc_phy_rx_iq_est_nphy(pi
, est
, num_samps
, wait_time
,
2443 wlc_phy_classifier_nphy(pi
, (0x7 << 0), classif_state
);
2444 wlapi_enable_mac(pi
->sh
->physhim
);
2446 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++)
2447 cmplx_pwr
[i
] = (est
[i
].i_pwr
+ est
[i
].q_pwr
) >>
2450 wlc_phy_noise_calc_phy(pi
, cmplx_pwr
, noise_dbm_ant
);
2452 for (i
= 0; i
< pi
->pubpi
.phy_corenum
; i
++) {
2453 pi
->nphy_noise_win
[i
][pi
->nphy_noise_index
] =
2456 if (noise_dbm_ant
[i
] > noise_dbm
)
2457 noise_dbm
= noise_dbm_ant
[i
];
2459 pi
->nphy_noise_index
= MODINC_POW2(pi
->nphy_noise_index
,
2460 PHY_NOISE_WINDOW_SZ
);
2462 wait_for_intr
= false;
2469 wlc_phy_noise_cb(pi
, ch
, noise_dbm
);
2473 void wlc_phy_noise_sample_request_external(struct brcms_phy_pub
*pih
)
2477 channel
= CHSPEC_CHANNEL(wlc_phy_chanspec_get(pih
));
2479 wlc_phy_noise_sample_request(pih
, PHY_NOISE_SAMPLE_EXTERNAL
, channel
);
2482 static const s8 lcnphy_gain_index_offset_for_pkt_rssi
[] = {
2523 void wlc_phy_compute_dB(u32
*cmplx_pwr
, s8
*p_cmplx_pwr_dB
, u8 core
)
2525 u8 msb
, secondmsb
, i
;
2528 for (i
= 0; i
< core
; i
++) {
2533 secondmsb
= (u8
) ((tmp
>> (--msb
- 1)) & 1);
2534 p_cmplx_pwr_dB
[i
] = (s8
) (3 * msb
+ 2 * secondmsb
);
2538 int wlc_phy_rssi_compute(struct brcms_phy_pub
*pih
,
2539 struct d11rxhdr
*rxh
)
2541 int rssi
= rxh
->PhyRxStatus_1
& PRXS1_JSSI_MASK
;
2542 uint radioid
= pih
->radioid
;
2543 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2545 if ((pi
->sh
->corerev
>= 11)
2546 && !(rxh
->RxStatus2
& RXS_PHYRXST_VALID
)) {
2547 rssi
= BRCMS_RSSI_INVALID
;
2552 u8 gidx
= (rxh
->PhyRxStatus_2
& 0xFC00) >> 10;
2553 struct brcms_phy_lcnphy
*pi_lcn
= pi
->u
.pi_lcnphy
;
2558 rssi
= rssi
+ lcnphy_gain_index_offset_for_pkt_rssi
[gidx
];
2559 if ((rssi
> -46) && (gidx
> 18))
2562 rssi
= rssi
+ pi_lcn
->lcnphy_pkteng_rssi_slope
;
2571 } else if (radioid
== BCM2055_ID
|| radioid
== BCM2056_ID
2572 || radioid
== BCM2057_ID
) {
2573 rssi
= wlc_phy_rssi_compute_nphy(pi
, rxh
);
2580 void wlc_phy_freqtrack_start(struct brcms_phy_pub
*pih
)
2585 void wlc_phy_freqtrack_end(struct brcms_phy_pub
*pih
)
2590 void wlc_phy_set_deaf(struct brcms_phy_pub
*ppi
, bool user_flag
)
2592 struct brcms_phy
*pi
;
2593 pi
= (struct brcms_phy
*) ppi
;
2596 wlc_lcnphy_deaf_mode(pi
, true);
2597 else if (ISNPHY(pi
))
2598 wlc_nphy_deaf_mode(pi
, true);
2601 void wlc_phy_watchdog(struct brcms_phy_pub
*pih
)
2603 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2604 bool delay_phy_cal
= false;
2607 if (!pi
->watchdog_override
)
2610 if (!(SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)))
2611 wlc_phy_noise_sample_request((struct brcms_phy_pub
*) pi
,
2612 PHY_NOISE_SAMPLE_MON
,
2616 if (pi
->phynoise_state
&& (pi
->sh
->now
- pi
->phynoise_now
) > 5)
2617 pi
->phynoise_state
= 0;
2619 if ((!pi
->phycal_txpower
) ||
2620 ((pi
->sh
->now
- pi
->phycal_txpower
) >= pi
->sh
->fast_timer
)) {
2622 if (!SCAN_INPROG_PHY(pi
) && wlc_phy_cal_txpower_recalc_sw(pi
))
2623 pi
->phycal_txpower
= pi
->sh
->now
;
2626 if ((SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)
2627 || ASSOC_INPROG_PHY(pi
)))
2630 if (ISNPHY(pi
) && !pi
->disable_percal
&& !delay_phy_cal
) {
2632 if ((pi
->nphy_perical
!= PHY_PERICAL_DISABLE
) &&
2633 (pi
->nphy_perical
!= PHY_PERICAL_MANUAL
) &&
2634 ((pi
->sh
->now
- pi
->nphy_perical_last
) >=
2635 pi
->sh
->glacial_timer
))
2636 wlc_phy_cal_perical((struct brcms_phy_pub
*) pi
,
2637 PHY_PERICAL_WATCHDOG
);
2639 wlc_phy_txpwr_papd_cal_nphy(pi
);
2643 if (pi
->phy_forcecal
||
2644 ((pi
->sh
->now
- pi
->phy_lastcal
) >=
2645 pi
->sh
->glacial_timer
)) {
2646 if (!(SCAN_RM_IN_PROGRESS(pi
) || ASSOC_INPROG_PHY(pi
)))
2647 wlc_lcnphy_calib_modes(
2649 LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL
);
2651 (SCAN_RM_IN_PROGRESS(pi
) || PLT_INPROG_PHY(pi
)
2652 || ASSOC_INPROG_PHY(pi
)
2653 || pi
->carrier_suppr_disable
2654 || pi
->disable_percal
))
2655 wlc_lcnphy_calib_modes(pi
,
2656 PHY_PERICAL_WATCHDOG
);
2661 void wlc_phy_BSSinit(struct brcms_phy_pub
*pih
, bool bonlyap
, int rssi
)
2663 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2667 for (i
= 0; i
< MA_WINDOW_SZ
; i
++)
2668 pi
->sh
->phy_noise_window
[i
] = (s8
) (rssi
& 0xff);
2670 for (i
= 0; i
< MA_WINDOW_SZ
; i
++)
2671 pi
->sh
->phy_noise_window
[i
] =
2672 PHY_NOISE_FIXED_VAL_LCNPHY
;
2674 pi
->sh
->phy_noise_index
= 0;
2676 for (i
= 0; i
< PHY_NOISE_WINDOW_SZ
; i
++) {
2677 for (k
= WL_ANT_IDX_1
; k
< WL_ANT_RX_MAX
; k
++)
2678 pi
->nphy_noise_win
[k
][i
] = PHY_NOISE_FIXED_VAL_NPHY
;
2680 pi
->nphy_noise_index
= 0;
2684 wlc_phy_papd_decode_epsilon(u32 epsilon
, s32
*eps_real
, s32
*eps_imag
)
2686 *eps_imag
= (epsilon
>> 13);
2687 if (*eps_imag
> 0xfff)
2688 *eps_imag
-= 0x2000;
2690 *eps_real
= (epsilon
& 0x1fff);
2691 if (*eps_real
> 0xfff)
2692 *eps_real
-= 0x2000;
2695 void wlc_phy_cal_perical_mphase_reset(struct brcms_phy
*pi
)
2697 wlapi_del_timer(pi
->phycal_timer
);
2699 pi
->cal_type_override
= PHY_PERICAL_AUTO
;
2700 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_IDLE
;
2701 pi
->mphase_txcal_cmdidx
= 0;
2705 wlc_phy_cal_perical_mphase_schedule(struct brcms_phy
*pi
, uint delay
)
2708 if ((pi
->nphy_perical
!= PHY_PERICAL_MPHASE
) &&
2709 (pi
->nphy_perical
!= PHY_PERICAL_MANUAL
))
2712 wlapi_del_timer(pi
->phycal_timer
);
2714 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_INIT
;
2715 wlapi_add_timer(pi
->phycal_timer
, delay
, 0);
2718 void wlc_phy_cal_perical(struct brcms_phy_pub
*pih
, u8 reason
)
2720 s16 nphy_currtemp
= 0;
2722 bool do_periodic_cal
= true;
2723 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2728 if ((pi
->nphy_perical
== PHY_PERICAL_DISABLE
) ||
2729 (pi
->nphy_perical
== PHY_PERICAL_MANUAL
))
2733 case PHY_PERICAL_DRIVERUP
:
2736 case PHY_PERICAL_PHYINIT
:
2737 if (pi
->nphy_perical
== PHY_PERICAL_MPHASE
) {
2738 if (PHY_PERICAL_MPHASE_PENDING(pi
))
2739 wlc_phy_cal_perical_mphase_reset(pi
);
2741 wlc_phy_cal_perical_mphase_schedule(
2743 PHY_PERICAL_INIT_DELAY
);
2747 case PHY_PERICAL_JOIN_BSS
:
2748 case PHY_PERICAL_START_IBSS
:
2749 case PHY_PERICAL_UP_BSS
:
2750 if ((pi
->nphy_perical
== PHY_PERICAL_MPHASE
) &&
2751 PHY_PERICAL_MPHASE_PENDING(pi
))
2752 wlc_phy_cal_perical_mphase_reset(pi
);
2754 pi
->first_cal_after_assoc
= true;
2756 pi
->cal_type_override
= PHY_PERICAL_FULL
;
2758 if (pi
->phycal_tempdelta
)
2759 pi
->nphy_lastcal_temp
= wlc_phy_tempsense_nphy(pi
);
2761 wlc_phy_cal_perical_nphy_run(pi
, PHY_PERICAL_FULL
);
2764 case PHY_PERICAL_WATCHDOG
:
2765 if (pi
->phycal_tempdelta
) {
2766 nphy_currtemp
= wlc_phy_tempsense_nphy(pi
);
2768 (nphy_currtemp
> pi
->nphy_lastcal_temp
) ?
2769 nphy_currtemp
- pi
->nphy_lastcal_temp
:
2770 pi
->nphy_lastcal_temp
- nphy_currtemp
;
2772 if ((delta_temp
< (s16
) pi
->phycal_tempdelta
) &&
2773 (pi
->nphy_txiqlocal_chanspec
==
2774 pi
->radio_chanspec
))
2775 do_periodic_cal
= false;
2777 pi
->nphy_lastcal_temp
= nphy_currtemp
;
2780 if (do_periodic_cal
) {
2781 if (pi
->nphy_perical
== PHY_PERICAL_MPHASE
) {
2782 if (!PHY_PERICAL_MPHASE_PENDING(pi
))
2783 wlc_phy_cal_perical_mphase_schedule(
2785 PHY_PERICAL_WDOG_DELAY
);
2786 } else if (pi
->nphy_perical
== PHY_PERICAL_SPHASE
)
2787 wlc_phy_cal_perical_nphy_run(pi
,
2796 void wlc_phy_cal_perical_mphase_restart(struct brcms_phy
*pi
)
2798 pi
->mphase_cal_phase_id
= MPHASE_CAL_STATE_INIT
;
2799 pi
->mphase_txcal_cmdidx
= 0;
2802 u8
wlc_phy_nbits(s32 value
)
2807 abs_val
= abs(value
);
2808 while ((abs_val
>> nbits
) > 0)
2814 void wlc_phy_stf_chain_init(struct brcms_phy_pub
*pih
, u8 txchain
, u8 rxchain
)
2816 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2818 pi
->sh
->hw_phytxchain
= txchain
;
2819 pi
->sh
->hw_phyrxchain
= rxchain
;
2820 pi
->sh
->phytxchain
= txchain
;
2821 pi
->sh
->phyrxchain
= rxchain
;
2822 pi
->pubpi
.phy_corenum
= (u8
)hweight8(pi
->sh
->phyrxchain
);
2825 void wlc_phy_stf_chain_set(struct brcms_phy_pub
*pih
, u8 txchain
, u8 rxchain
)
2827 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2829 pi
->sh
->phytxchain
= txchain
;
2832 wlc_phy_rxcore_setstate_nphy(pih
, rxchain
);
2834 pi
->pubpi
.phy_corenum
= (u8
)hweight8(pi
->sh
->phyrxchain
);
2837 void wlc_phy_stf_chain_get(struct brcms_phy_pub
*pih
, u8
*txchain
, u8
*rxchain
)
2839 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2841 *txchain
= pi
->sh
->phytxchain
;
2842 *rxchain
= pi
->sh
->phyrxchain
;
2845 u8
wlc_phy_stf_chain_active_get(struct brcms_phy_pub
*pih
)
2849 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2851 active_bitmap
= (pi
->phy_txcore_heatedup
) ? 0x31 : 0x33;
2853 if (!pi
->watchdog_override
)
2854 return active_bitmap
;
2856 if (NREV_GE(pi
->pubpi
.phy_rev
, 6)) {
2857 wlapi_suspend_mac_and_wait(pi
->sh
->physhim
);
2858 nphy_currtemp
= wlc_phy_tempsense_nphy(pi
);
2859 wlapi_enable_mac(pi
->sh
->physhim
);
2861 if (!pi
->phy_txcore_heatedup
) {
2862 if (nphy_currtemp
>= pi
->phy_txcore_disable_temp
) {
2863 active_bitmap
&= 0xFD;
2864 pi
->phy_txcore_heatedup
= true;
2867 if (nphy_currtemp
<= pi
->phy_txcore_enable_temp
) {
2868 active_bitmap
|= 0x2;
2869 pi
->phy_txcore_heatedup
= false;
2874 return active_bitmap
;
2877 s8
wlc_phy_stf_ssmode_get(struct brcms_phy_pub
*pih
, u16 chanspec
)
2879 struct brcms_phy
*pi
= (struct brcms_phy
*) pih
;
2880 u8 siso_mcs_id
, cdd_mcs_id
;
2883 (CHSPEC_IS40(chanspec
)) ? TXP_FIRST_MCS_40_SISO
:
2884 TXP_FIRST_MCS_20_SISO
;
2886 (CHSPEC_IS40(chanspec
)) ? TXP_FIRST_MCS_40_CDD
:
2887 TXP_FIRST_MCS_20_CDD
;
2889 if (pi
->tx_power_target
[siso_mcs_id
] >
2890 (pi
->tx_power_target
[cdd_mcs_id
] + 12))
2891 return PHY_TXC1_MODE_SISO
;
2893 return PHY_TXC1_MODE_CDD
;
2896 const u8
*wlc_phy_get_ofdm_rate_lookup(void)
2898 return ofdm_rate_lookup
;
2901 void wlc_lcnphy_epa_switch(struct brcms_phy
*pi
, bool mode
)
2903 if ((pi
->sh
->chip
== BCMA_CHIP_ID_BCM4313
) &&
2904 (pi
->sh
->boardflags
& BFL_FEM
)) {
2907 txant
= wlapi_bmac_get_txant(pi
->sh
->physhim
);
2909 mod_phy_reg(pi
, 0x44d, (0x1 << 2), (1) << 2);
2911 mod_phy_reg(pi
, 0x44c, (0x1 << 2), (1) << 2);
2914 ai_cc_reg(pi
->sh
->sih
,
2915 offsetof(struct chipcregs
, gpiocontrol
),
2917 ai_cc_reg(pi
->sh
->sih
,
2918 offsetof(struct chipcregs
, gpioout
),
2920 ai_cc_reg(pi
->sh
->sih
,
2921 offsetof(struct chipcregs
, gpioouten
),
2924 mod_phy_reg(pi
, 0x44c, (0x1 << 2), (0) << 2);
2926 mod_phy_reg(pi
, 0x44d, (0x1 << 2), (0) << 2);
2928 ai_cc_reg(pi
->sh
->sih
,
2929 offsetof(struct chipcregs
, gpioout
),
2931 ai_cc_reg(pi
->sh
->sih
,
2932 offsetof(struct chipcregs
, gpioouten
),
2934 ai_cc_reg(pi
->sh
->sih
,
2935 offsetof(struct chipcregs
, gpiocontrol
),
2941 void wlc_phy_ldpc_override_set(struct brcms_phy_pub
*ppi
, bool ldpc
)
2947 wlc_phy_get_pwrdet_offsets(struct brcms_phy
*pi
, s8
*cckoffset
, s8
*ofdmoffset
)
2953 s8
wlc_phy_upd_rssi_offset(struct brcms_phy
*pi
, s8 rssi
, u16 chanspec
)
2959 bool wlc_phy_txpower_ipa_ison(struct brcms_phy_pub
*ppi
)
2961 struct brcms_phy
*pi
= (struct brcms_phy
*) ppi
;
2964 return wlc_phy_n_txpower_ipa_ison(pi
);