25ea00342f525bbe80b7568acebc8b91b68d097d
[cascardo/linux.git] / drivers / staging / brcm80211 / brcmsmac / phy / phy_int.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 #ifndef _BRCM_PHY_INT_H_
18 #define _BRCM_PHY_INT_H_
19
20 #include <types.h>
21 #include <brcmu_utils.h>
22 #include <brcmu_wifi.h>
23
24 #define PHY_VERSION                     { 1, 82, 8, 0 }
25
26 #define PHYHAL_ERROR    0x0001
27 #define PHYHAL_TRACE    0x0002
28 #define PHYHAL_INFORM   0x0004
29
30 extern u32 phyhal_msg_level;
31
32 #define PHY_INFORM_ON()         (phyhal_msg_level & PHYHAL_INFORM)
33 #define PHY_THERMAL_ON()        (phyhal_msg_level & PHYHAL_THERMAL)
34 #define PHY_CAL_ON()            (phyhal_msg_level & PHYHAL_CAL)
35
36 #ifdef BOARD_TYPE
37 #define BOARDTYPE(_type) BOARD_TYPE
38 #else
39 #define BOARDTYPE(_type) _type
40 #endif
41
42 #define LCNXN_BASEREV           16
43
44 struct brcms_phy_srom_fem {
45         /* TSSI positive slope, 1: positive, 0: negative */
46         u8 tssipos;
47         /* Ext PA gain-type: full-gain: 0, pa-lite: 1, no_pa: 2 */
48         u8 extpagain;
49         /* support 32 combinations of different Pdet dynamic ranges */
50         u8 pdetrange;
51         /* TR switch isolation */
52         u8 triso;
53         /* antswctrl lookup table configuration: 32 possible choices */
54         u8 antswctrllut;
55 };
56
57 #undef ISNPHY
58 #undef ISLCNPHY
59 #define ISNPHY(pi)      PHYTYPE_IS((pi)->pubpi.phy_type, PHY_TYPE_N)
60 #define ISLCNPHY(pi)    PHYTYPE_IS((pi)->pubpi.phy_type, PHY_TYPE_LCN)
61
62 #define ISPHY_11N_CAP(pi)       (ISNPHY(pi) || ISLCNPHY(pi))
63
64 #define IS20MHZ(pi)     ((pi)->bw == WL_CHANSPEC_BW_20)
65 #define IS40MHZ(pi)     ((pi)->bw == WL_CHANSPEC_BW_40)
66
67 #define PHY_GET_RFATTN(rfgain)  ((rfgain) & 0x0f)
68 #define PHY_GET_PADMIX(rfgain)  (((rfgain) & 0x10) >> 4)
69 #define PHY_GET_RFGAINID(rfattn, padmix, width) ((rfattn) + ((padmix)*(width)))
70 #define PHY_SAT(x, n)           ((x) > ((1<<((n)-1))-1) ? ((1<<((n)-1))-1) : \
71                                 ((x) < -(1<<((n)-1)) ? -(1<<((n)-1)) : (x)))
72 #define PHY_SHIFT_ROUND(x, n)   ((x) >= 0 ? ((x)+(1<<((n)-1)))>>(n) : (x)>>(n))
73 #define PHY_HW_ROUND(x, s)              ((x >> s) + ((x >> (s-1)) & (s != 0)))
74
75 #define CH_5G_GROUP     3
76 #define A_LOW_CHANS     0
77 #define A_MID_CHANS     1
78 #define A_HIGH_CHANS    2
79 #define CH_2G_GROUP     1
80 #define G_ALL_CHANS     0
81
82 #define FIRST_REF5_CHANNUM      149
83 #define LAST_REF5_CHANNUM       165
84 #define FIRST_5G_CHAN           14
85 #define LAST_5G_CHAN            50
86 #define FIRST_MID_5G_CHAN       14
87 #define LAST_MID_5G_CHAN        35
88 #define FIRST_HIGH_5G_CHAN      36
89 #define LAST_HIGH_5G_CHAN       41
90 #define FIRST_LOW_5G_CHAN       42
91 #define LAST_LOW_5G_CHAN        50
92
93 #define BASE_LOW_5G_CHAN        4900
94 #define BASE_MID_5G_CHAN        5100
95 #define BASE_HIGH_5G_CHAN       5500
96
97 #define CHAN5G_FREQ(chan)  (5000 + chan*5)
98 #define CHAN2G_FREQ(chan)  (2407 + chan*5)
99
100 #define TXP_FIRST_CCK           0
101 #define TXP_LAST_CCK            3
102 #define TXP_FIRST_OFDM          4
103 #define TXP_LAST_OFDM           11
104 #define TXP_FIRST_OFDM_20_CDD   12
105 #define TXP_LAST_OFDM_20_CDD    19
106 #define TXP_FIRST_MCS_20_SISO   20
107 #define TXP_LAST_MCS_20_SISO    27
108 #define TXP_FIRST_MCS_20_CDD    28
109 #define TXP_LAST_MCS_20_CDD     35
110 #define TXP_FIRST_MCS_20_STBC   36
111 #define TXP_LAST_MCS_20_STBC    43
112 #define TXP_FIRST_MCS_20_SDM    44
113 #define TXP_LAST_MCS_20_SDM     51
114 #define TXP_FIRST_OFDM_40_SISO  52
115 #define TXP_LAST_OFDM_40_SISO   59
116 #define TXP_FIRST_OFDM_40_CDD   60
117 #define TXP_LAST_OFDM_40_CDD    67
118 #define TXP_FIRST_MCS_40_SISO   68
119 #define TXP_LAST_MCS_40_SISO    75
120 #define TXP_FIRST_MCS_40_CDD    76
121 #define TXP_LAST_MCS_40_CDD     83
122 #define TXP_FIRST_MCS_40_STBC   84
123 #define TXP_LAST_MCS_40_STBC    91
124 #define TXP_FIRST_MCS_40_SDM    92
125 #define TXP_LAST_MCS_40_SDM     99
126 #define TXP_MCS_32              100
127 #define TXP_NUM_RATES           101
128 #define ADJ_PWR_TBL_LEN         84
129
130 #define TXP_FIRST_SISO_MCS_20   20
131 #define TXP_LAST_SISO_MCS_20    27
132
133 #define PHY_CORE_NUM_1  1
134 #define PHY_CORE_NUM_2  2
135 #define PHY_CORE_NUM_3  3
136 #define PHY_CORE_NUM_4  4
137 #define PHY_CORE_MAX    PHY_CORE_NUM_4
138 #define PHY_CORE_0      0
139 #define PHY_CORE_1      1
140 #define PHY_CORE_2      2
141 #define PHY_CORE_3      3
142
143 #define MA_WINDOW_SZ            8
144
145 #define PHY_NOISE_SAMPLE_MON            1
146 #define PHY_NOISE_SAMPLE_EXTERNAL       2
147 #define PHY_NOISE_WINDOW_SZ     16
148 #define PHY_NOISE_GLITCH_INIT_MA 10
149 #define PHY_NOISE_GLITCH_INIT_MA_BADPlCP 10
150 #define PHY_NOISE_STATE_MON             0x1
151 #define PHY_NOISE_STATE_EXTERNAL        0x2
152 #define PHY_NOISE_SAMPLE_LOG_NUM_NPHY   10
153 #define PHY_NOISE_SAMPLE_LOG_NUM_UCODE  9
154
155 #define PHY_NOISE_OFFSETFACT_4322  (-103)
156 #define PHY_NOISE_MA_WINDOW_SZ  2
157
158 #define PHY_RSSI_TABLE_SIZE     64
159 #define RSSI_ANT_MERGE_MAX      0
160 #define RSSI_ANT_MERGE_MIN      1
161 #define RSSI_ANT_MERGE_AVG      2
162
163 #define PHY_TSSI_TABLE_SIZE     64
164 #define APHY_TSSI_TABLE_SIZE    256
165 #define TX_GAIN_TABLE_LENGTH    64
166 #define DEFAULT_11A_TXP_IDX     24
167 #define NUM_TSSI_FRAMES        4
168 #define NULL_TSSI               0x7f
169 #define NULL_TSSI_W             0x7f7f
170
171 #define PHY_PAPD_EPS_TBL_SIZE_LCNPHY 64
172
173 #define LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL 9
174
175 #define PHY_TXPWR_MIN           10
176 #define PHY_TXPWR_MIN_NPHY      8
177 #define RADIOPWR_OVERRIDE_DEF   (-1)
178
179 #define PWRTBL_NUM_COEFF        3
180
181 #define SPURAVOID_DISABLE       0
182 #define SPURAVOID_AUTO          1
183 #define SPURAVOID_FORCEON       2
184 #define SPURAVOID_FORCEON2      3
185
186 #define PHY_SW_TIMER_FAST               15
187 #define PHY_SW_TIMER_SLOW               60
188 #define PHY_SW_TIMER_GLACIAL    120
189
190 #define PHY_PERICAL_AUTO        0
191 #define PHY_PERICAL_FULL        1
192 #define PHY_PERICAL_PARTIAL     2
193
194 #define PHY_PERICAL_NODELAY     0
195 #define PHY_PERICAL_INIT_DELAY  5
196 #define PHY_PERICAL_ASSOC_DELAY 5
197 #define PHY_PERICAL_WDOG_DELAY  5
198
199 #define MPHASE_TXCAL_NUMCMDS    2
200
201 #define PHY_PERICAL_MPHASE_PENDING(pi) \
202         (pi->mphase_cal_phase_id > MPHASE_CAL_STATE_IDLE)
203
204 enum {
205         MPHASE_CAL_STATE_IDLE = 0,
206         MPHASE_CAL_STATE_INIT = 1,
207         MPHASE_CAL_STATE_TXPHASE0,
208         MPHASE_CAL_STATE_TXPHASE1,
209         MPHASE_CAL_STATE_TXPHASE2,
210         MPHASE_CAL_STATE_TXPHASE3,
211         MPHASE_CAL_STATE_TXPHASE4,
212         MPHASE_CAL_STATE_TXPHASE5,
213         MPHASE_CAL_STATE_PAPDCAL,
214         MPHASE_CAL_STATE_RXCAL,
215         MPHASE_CAL_STATE_RSSICAL,
216         MPHASE_CAL_STATE_IDLETSSI
217 };
218
219 enum phy_cal_mode {
220         CAL_FULL,
221         CAL_RECAL,
222         CAL_CURRECAL,
223         CAL_DIGCAL,
224         CAL_GCTRL,
225         CAL_SOFT,
226         CAL_DIGLO
227 };
228
229 #define RDR_NTIERS  1
230 #define RDR_TIER_SIZE 64
231 #define RDR_LIST_SIZE (512/3)
232 #define RDR_EPOCH_SIZE 40
233 #define RDR_NANTENNAS 2
234 #define RDR_NTIER_SIZE  RDR_LIST_SIZE
235 #define RDR_LP_BUFFER_SIZE 64
236 #define LP_LEN_HIS_SIZE 10
237
238 #define STATIC_NUM_RF 32
239 #define STATIC_NUM_BB 9
240
241 #define BB_MULT_MASK            0x0000ffff
242 #define BB_MULT_VALID_MASK      0x80000000
243
244 #define CORDIC_AG       39797
245 #define CORDIC_NI       18
246 #define FIXED(X)        ((s32)((X) << 16))
247
248 #define FLOAT(X) \
249         (((X) >= 0) ? ((((X) >> 15) + 1) >> 1) : -((((-(X)) >> 15) + 1) >> 1))
250
251 #define PHY_CHAIN_TX_DISABLE_TEMP       115
252 #define PHY_HYSTERESIS_DELTATEMP        5
253
254 #define PHY_BITSCNT(x)  brcmu_bitcount((u8 *)&(x), sizeof(u8))
255
256 #define MOD_PHY_REG(pi, phy_type, reg_name, field, value) \
257         mod_phy_reg(pi, phy_type##_##reg_name, \
258                     phy_type##_##reg_name##_##field##_MASK, \
259                     (value) << phy_type##_##reg_name##_##field##_##SHIFT)
260
261 #define READ_PHY_REG(pi, phy_type, reg_name, field) \
262         ((read_phy_reg(pi, phy_type##_##reg_name) & \
263           phy_type##_##reg_name##_##field##_##MASK) \
264          >> phy_type##_##reg_name##_##field##_##SHIFT)
265
266 #define VALID_PHYTYPE(phytype)  (((uint)phytype == PHY_TYPE_N) || \
267                                 ((uint)phytype == PHY_TYPE_LCN))
268
269 #define VALID_N_RADIO(radioid) ((radioid == BCM2055_ID) || \
270                                  (radioid == BCM2056_ID) || \
271                                  (radioid == BCM2057_ID))
272
273 #define VALID_LCN_RADIO(radioid)        (radioid == BCM2064_ID)
274
275 #define VALID_RADIO(pi, radioid)        ( \
276                 (ISNPHY(pi) ? VALID_N_RADIO(radioid) : false) || \
277                 (ISLCNPHY(pi) ? VALID_LCN_RADIO(radioid) : false))
278
279 #define SCAN_INPROG_PHY(pi) \
280         (mboolisset(pi->measure_hold, PHY_HOLD_FOR_SCAN))
281
282 #define RM_INPROG_PHY(pi)       (mboolisset(pi->measure_hold, PHY_HOLD_FOR_RM))
283
284 #define PLT_INPROG_PHY(pi)      (mboolisset(pi->measure_hold, PHY_HOLD_FOR_PLT))
285
286 #define ASSOC_INPROG_PHY(pi) \
287         (mboolisset(pi->measure_hold, PHY_HOLD_FOR_ASSOC))
288
289 #define SCAN_RM_IN_PROGRESS(pi) \
290         (mboolisset(pi->measure_hold, PHY_HOLD_FOR_SCAN | PHY_HOLD_FOR_RM))
291
292 #define PHY_MUTED(pi) \
293         (mboolisset(pi->measure_hold, PHY_HOLD_FOR_MUTE))
294
295 #define PUB_NOT_ASSOC(pi) \
296         (mboolisset(pi->measure_hold, PHY_HOLD_FOR_NOT_ASSOC))
297
298 #if defined(EXT_CBALL)
299 #define NORADIO_ENAB(pub) ((pub).radioid == NORADIO_ID)
300 #else
301 #define NORADIO_ENAB(pub) 0
302 #endif
303
304 #define PHY_LTRN_LIST_LEN       64
305 extern u16 ltrn_list[PHY_LTRN_LIST_LEN];
306
307 struct phy_table_info {
308         uint table;
309         int q;
310         uint max;
311 };
312
313 struct phytbl_info {
314         const void *tbl_ptr;
315         u32 tbl_len;
316         u32 tbl_id;
317         u32 tbl_offset;
318         u32 tbl_width;
319 };
320
321 struct interference_info {
322         u8 curr_home_channel;
323         u16 crsminpwrthld_40_stored;
324         u16 crsminpwrthld_20L_stored;
325         u16 crsminpwrthld_20U_stored;
326         u16 init_gain_code_core1_stored;
327         u16 init_gain_code_core2_stored;
328         u16 init_gain_codeb_core1_stored;
329         u16 init_gain_codeb_core2_stored;
330         u16 init_gain_table_stored[4];
331
332         u16 clip1_hi_gain_code_core1_stored;
333         u16 clip1_hi_gain_code_core2_stored;
334         u16 clip1_hi_gain_codeb_core1_stored;
335         u16 clip1_hi_gain_codeb_core2_stored;
336         u16 nb_clip_thresh_core1_stored;
337         u16 nb_clip_thresh_core2_stored;
338         u16 init_ofdmlna2gainchange_stored[4];
339         u16 init_ccklna2gainchange_stored[4];
340         u16 clip1_lo_gain_code_core1_stored;
341         u16 clip1_lo_gain_code_core2_stored;
342         u16 clip1_lo_gain_codeb_core1_stored;
343         u16 clip1_lo_gain_codeb_core2_stored;
344         u16 w1_clip_thresh_core1_stored;
345         u16 w1_clip_thresh_core2_stored;
346         u16 radio_2056_core1_rssi_gain_stored;
347         u16 radio_2056_core2_rssi_gain_stored;
348         u16 energy_drop_timeout_len_stored;
349
350         u16 ed_crs40_assertthld0_stored;
351         u16 ed_crs40_assertthld1_stored;
352         u16 ed_crs40_deassertthld0_stored;
353         u16 ed_crs40_deassertthld1_stored;
354         u16 ed_crs20L_assertthld0_stored;
355         u16 ed_crs20L_assertthld1_stored;
356         u16 ed_crs20L_deassertthld0_stored;
357         u16 ed_crs20L_deassertthld1_stored;
358         u16 ed_crs20U_assertthld0_stored;
359         u16 ed_crs20U_assertthld1_stored;
360         u16 ed_crs20U_deassertthld0_stored;
361         u16 ed_crs20U_deassertthld1_stored;
362
363         u16 badplcp_ma;
364         u16 badplcp_ma_previous;
365         u16 badplcp_ma_total;
366         u16 badplcp_ma_list[MA_WINDOW_SZ];
367         int badplcp_ma_index;
368         s16 pre_badplcp_cnt;
369         s16 bphy_pre_badplcp_cnt;
370
371         u16 init_gain_core1;
372         u16 init_gain_core2;
373         u16 init_gainb_core1;
374         u16 init_gainb_core2;
375         u16 init_gain_rfseq[4];
376
377         u16 crsminpwr0;
378         u16 crsminpwrl0;
379         u16 crsminpwru0;
380
381         s16 crsminpwr_index;
382
383         u16 radio_2057_core1_rssi_wb1a_gc_stored;
384         u16 radio_2057_core2_rssi_wb1a_gc_stored;
385         u16 radio_2057_core1_rssi_wb1g_gc_stored;
386         u16 radio_2057_core2_rssi_wb1g_gc_stored;
387         u16 radio_2057_core1_rssi_wb2_gc_stored;
388         u16 radio_2057_core2_rssi_wb2_gc_stored;
389         u16 radio_2057_core1_rssi_nb_gc_stored;
390         u16 radio_2057_core2_rssi_nb_gc_stored;
391 };
392
393 struct aci_save_gphy {
394         u16 rc_cal_ovr;
395         u16 phycrsth1;
396         u16 phycrsth2;
397         u16 init_n1p1_gain;
398         u16 p1_p2_gain;
399         u16 n1_n2_gain;
400         u16 n1_p1_gain;
401         u16 div_search_gain;
402         u16 div_p1_p2_gain;
403         u16 div_search_gn_change;
404         u16 table_7_2;
405         u16 table_7_3;
406         u16 cckshbits_gnref;
407         u16 clip_thresh;
408         u16 clip2_thresh;
409         u16 clip3_thresh;
410         u16 clip_p2_thresh;
411         u16 clip_pwdn_thresh;
412         u16 clip_n1p1_thresh;
413         u16 clip_n1_pwdn_thresh;
414         u16 bbconfig;
415         u16 cthr_sthr_shdin;
416         u16 energy;
417         u16 clip_p1_p2_thresh;
418         u16 threshold;
419         u16 reg15;
420         u16 reg16;
421         u16 reg17;
422         u16 div_srch_idx;
423         u16 div_srch_p1_p2;
424         u16 div_srch_gn_back;
425         u16 ant_dwell;
426         u16 ant_wr_settle;
427 };
428
429 struct lo_complex_abgphy_info {
430         s8 i;
431         s8 q;
432 };
433
434 struct nphy_iq_comp {
435         s16 a0;
436         s16 b0;
437         s16 a1;
438         s16 b1;
439 };
440
441 struct nphy_txpwrindex {
442         s8 index;
443         s8 index_internal;
444         s8 index_internal_save;
445         u16 AfectrlOverride;
446         u16 AfeCtrlDacGain;
447         u16 rad_gain;
448         u8 bbmult;
449         u16 iqcomp_a;
450         u16 iqcomp_b;
451         u16 locomp;
452 };
453
454 struct txiqcal_cache {
455
456         u16 txcal_coeffs_2G[8];
457         u16 txcal_radio_regs_2G[8];
458         struct nphy_iq_comp rxcal_coeffs_2G;
459
460         u16 txcal_coeffs_5G[8];
461         u16 txcal_radio_regs_5G[8];
462         struct nphy_iq_comp rxcal_coeffs_5G;
463 };
464
465 struct nphy_pwrctrl {
466         s8 max_pwr_2g;
467         s8 idle_targ_2g;
468         s16 pwrdet_2g_a1;
469         s16 pwrdet_2g_b0;
470         s16 pwrdet_2g_b1;
471         s8 max_pwr_5gm;
472         s8 idle_targ_5gm;
473         s8 max_pwr_5gh;
474         s8 max_pwr_5gl;
475         s16 pwrdet_5gm_a1;
476         s16 pwrdet_5gm_b0;
477         s16 pwrdet_5gm_b1;
478         s16 pwrdet_5gl_a1;
479         s16 pwrdet_5gl_b0;
480         s16 pwrdet_5gl_b1;
481         s16 pwrdet_5gh_a1;
482         s16 pwrdet_5gh_b0;
483         s16 pwrdet_5gh_b1;
484         s8 idle_targ_5gl;
485         s8 idle_targ_5gh;
486         s8 idle_tssi_2g;
487         s8 idle_tssi_5g;
488         s8 idle_tssi;
489         s16 a1;
490         s16 b0;
491         s16 b1;
492 };
493
494 struct nphy_txgains {
495         u16 txlpf[2];
496         u16 txgm[2];
497         u16 pga[2];
498         u16 pad[2];
499         u16 ipa[2];
500 };
501
502 #define PHY_NOISEVAR_BUFSIZE 10
503
504 struct nphy_noisevar_buf {
505         int bufcount;
506         int tone_id[PHY_NOISEVAR_BUFSIZE];
507         u32 noise_vars[PHY_NOISEVAR_BUFSIZE];
508         u32 min_noise_vars[PHY_NOISEVAR_BUFSIZE];
509 };
510
511 struct rssical_cache {
512         u16 rssical_radio_regs_2G[2];
513         u16 rssical_phyregs_2G[12];
514
515         u16 rssical_radio_regs_5G[2];
516         u16 rssical_phyregs_5G[12];
517 };
518
519 struct lcnphy_cal_results {
520
521         u16 txiqlocal_a;
522         u16 txiqlocal_b;
523         u16 txiqlocal_didq;
524         u8 txiqlocal_ei0;
525         u8 txiqlocal_eq0;
526         u8 txiqlocal_fi0;
527         u8 txiqlocal_fq0;
528
529         u16 txiqlocal_bestcoeffs[11];
530         u16 txiqlocal_bestcoeffs_valid;
531
532         u32 papd_eps_tbl[PHY_PAPD_EPS_TBL_SIZE_LCNPHY];
533         u16 analog_gain_ref;
534         u16 lut_begin;
535         u16 lut_end;
536         u16 lut_step;
537         u16 rxcompdbm;
538         u16 papdctrl;
539         u16 sslpnCalibClkEnCtrl;
540
541         u16 rxiqcal_coeff_a0;
542         u16 rxiqcal_coeff_b0;
543 };
544
545 struct shared_phy {
546         struct brcms_phy *phy_head;
547         uint unit;
548         struct si_pub *sih;
549         void *physhim;
550         uint corerev;
551         u32 machwcap;
552         bool up;
553         bool clk;
554         uint now;
555         u16 vid;
556         u16 did;
557         uint chip;
558         uint chiprev;
559         uint chippkg;
560         uint sromrev;
561         uint boardtype;
562         uint boardrev;
563         uint boardvendor;
564         u32 boardflags;
565         u32 boardflags2;
566         uint bustype;
567         uint buscorerev;
568         uint fast_timer;
569         uint slow_timer;
570         uint glacial_timer;
571         u8 rx_antdiv;
572         s8 phy_noise_window[MA_WINDOW_SZ];
573         uint phy_noise_index;
574         u8 hw_phytxchain;
575         u8 hw_phyrxchain;
576         u8 phytxchain;
577         u8 phyrxchain;
578         u8 rssi_mode;
579         bool _rifs_phy;
580 };
581
582 struct brcms_phy_pub {
583         uint phy_type;
584         uint phy_rev;
585         u8 phy_corenum;
586         u16 radioid;
587         u8 radiorev;
588         u8 radiover;
589
590         uint coreflags;
591         uint ana_rev;
592         bool abgphy_encore;
593 };
594
595 struct phy_func_ptr {
596         void (*init)(struct brcms_phy *);
597         void (*calinit)(struct brcms_phy *);
598         void (*chanset)(struct brcms_phy *, u16 chanspec);
599         void (*txpwrrecalc)(struct brcms_phy *);
600         int (*longtrn)(struct brcms_phy *, int);
601         void (*txiqccget)(struct brcms_phy *, u16 *, u16 *);
602         void (*txiqccset)(struct brcms_phy *, u16, u16);
603         u16 (*txloccget)(struct brcms_phy *);
604         void (*radioloftget)(struct brcms_phy *, u8 *, u8 *, u8 *, u8 *);
605         void (*carrsuppr)(struct brcms_phy *);
606         s32 (*rxsigpwr)(struct brcms_phy *, s32);
607         void (*detach)(struct brcms_phy *);
608 };
609
610 struct brcms_phy {
611         struct brcms_phy_pub pubpi_ro;
612         struct shared_phy *sh;
613         struct phy_func_ptr pi_fptr;
614         void *pi_ptr;
615
616         union {
617                 struct brcms_phy_lcnphy *pi_lcnphy;
618         } u;
619         bool user_txpwr_at_rfport;
620
621         struct d11regs *regs;
622         struct brcms_phy *next;
623         char *vars;
624         struct brcms_phy_pub pubpi;
625
626         bool do_initcal;
627         bool phytest_on;
628         bool ofdm_rateset_war;
629         bool bf_preempt_4306;
630         u16 radio_chanspec;
631         u8 antsel_type;
632         u16 bw;
633         u8 txpwr_percent;
634         bool phy_init_por;
635
636         bool init_in_progress;
637         bool initialized;
638         bool sbtml_gm;
639         uint refcnt;
640         bool watchdog_override;
641         u8 phynoise_state;
642         uint phynoise_now;
643         int phynoise_chan_watchdog;
644         bool phynoise_polling;
645         bool disable_percal;
646         u32 measure_hold;
647
648         s16 txpa_2g[PWRTBL_NUM_COEFF];
649         s16 txpa_2g_low_temp[PWRTBL_NUM_COEFF];
650         s16 txpa_2g_high_temp[PWRTBL_NUM_COEFF];
651         s16 txpa_5g_low[PWRTBL_NUM_COEFF];
652         s16 txpa_5g_mid[PWRTBL_NUM_COEFF];
653         s16 txpa_5g_hi[PWRTBL_NUM_COEFF];
654
655         u8 tx_srom_max_2g;
656         u8 tx_srom_max_5g_low;
657         u8 tx_srom_max_5g_mid;
658         u8 tx_srom_max_5g_hi;
659         u8 tx_srom_max_rate_2g[TXP_NUM_RATES];
660         u8 tx_srom_max_rate_5g_low[TXP_NUM_RATES];
661         u8 tx_srom_max_rate_5g_mid[TXP_NUM_RATES];
662         u8 tx_srom_max_rate_5g_hi[TXP_NUM_RATES];
663         u8 tx_user_target[TXP_NUM_RATES];
664         s8 tx_power_offset[TXP_NUM_RATES];
665         u8 tx_power_target[TXP_NUM_RATES];
666
667         struct brcms_phy_srom_fem srom_fem2g;
668         struct brcms_phy_srom_fem srom_fem5g;
669
670         u8 tx_power_max;
671         u8 tx_power_max_rate_ind;
672         bool hwpwrctrl;
673         u8 nphy_txpwrctrl;
674         s8 nphy_txrx_chain;
675         bool phy_5g_pwrgain;
676
677         u16 phy_wreg;
678         u16 phy_wreg_limit;
679
680         s8 n_preamble_override;
681         u8 antswitch;
682         u8 aa2g, aa5g;
683
684         s8 idle_tssi[CH_5G_GROUP];
685         s8 target_idle_tssi;
686         s8 txpwr_est_Pout;
687         u8 tx_power_min;
688         u8 txpwr_limit[TXP_NUM_RATES];
689         u8 txpwr_env_limit[TXP_NUM_RATES];
690         u8 adj_pwr_tbl_nphy[ADJ_PWR_TBL_LEN];
691
692         bool channel_14_wide_filter;
693
694         bool txpwroverride;
695         bool txpwridx_override_aphy;
696         s16 radiopwr_override;
697         u16 hwpwr_txcur;
698         u8 saved_txpwr_idx;
699
700         bool edcrs_threshold_lock;
701
702         u32 tr_R_gain_val;
703         u32 tr_T_gain_val;
704
705         s16 ofdm_analog_filt_bw_override;
706         s16 cck_analog_filt_bw_override;
707         s16 ofdm_rccal_override;
708         s16 cck_rccal_override;
709         u16 extlna_type;
710
711         uint interference_mode_crs_time;
712         u16 crsglitch_prev;
713         bool interference_mode_crs;
714
715         u32 phy_tx_tone_freq;
716         uint phy_lastcal;
717         bool phy_forcecal;
718         bool phy_fixed_noise;
719         u32 xtalfreq;
720         u8 pdiv;
721         s8 carrier_suppr_disable;
722
723         bool phy_bphy_evm;
724         bool phy_bphy_rfcs;
725         s8 phy_scraminit;
726         u8 phy_gpiosel;
727
728         s16 phy_txcore_disable_temp;
729         s16 phy_txcore_enable_temp;
730         s8 phy_tempsense_offset;
731         bool phy_txcore_heatedup;
732
733         u16 radiopwr;
734         u16 bb_atten;
735         u16 txctl1;
736
737         u16 mintxbias;
738         u16 mintxmag;
739         struct lo_complex_abgphy_info gphy_locomp_iq
740                         [STATIC_NUM_RF][STATIC_NUM_BB];
741         s8 stats_11b_txpower[STATIC_NUM_RF][STATIC_NUM_BB];
742         u16 gain_table[TX_GAIN_TABLE_LENGTH];
743         bool loopback_gain;
744         s16 max_lpback_gain_hdB;
745         s16 trsw_rx_gain_hdB;
746         u8 power_vec[8];
747
748         u16 rc_cal;
749         int nrssi_table_delta;
750         int nrssi_slope_scale;
751         int nrssi_slope_offset;
752         int min_rssi;
753         int max_rssi;
754
755         s8 txpwridx;
756         u8 min_txpower;
757
758         u8 a_band_high_disable;
759
760         u16 tx_vos;
761         u16 global_tx_bb_dc_bias_loft;
762
763         int rf_max;
764         int bb_max;
765         int rf_list_size;
766         int bb_list_size;
767         u16 *rf_attn_list;
768         u16 *bb_attn_list;
769         u16 padmix_mask;
770         u16 padmix_reg;
771         u16 *txmag_list;
772         uint txmag_len;
773         bool txmag_enable;
774
775         s8 *a_tssi_to_dbm;
776         s8 *m_tssi_to_dbm;
777         s8 *l_tssi_to_dbm;
778         s8 *h_tssi_to_dbm;
779         u8 *hwtxpwr;
780
781         u16 freqtrack_saved_regs[2];
782         int cur_interference_mode;
783         bool hwpwrctrl_capable;
784         bool temppwrctrl_capable;
785
786         uint phycal_nslope;
787         uint phycal_noffset;
788         uint phycal_mlo;
789         uint phycal_txpower;
790
791         u8 phy_aa2g;
792
793         bool nphy_tableloaded;
794         s8 nphy_rssisel;
795         u32 nphy_bb_mult_save;
796         u16 nphy_txiqlocal_bestc[11];
797         bool nphy_txiqlocal_coeffsvalid;
798         struct nphy_txpwrindex nphy_txpwrindex[PHY_CORE_NUM_2];
799         struct nphy_pwrctrl nphy_pwrctrl_info[PHY_CORE_NUM_2];
800         u16 cck2gpo;
801         u32 ofdm2gpo;
802         u32 ofdm5gpo;
803         u32 ofdm5glpo;
804         u32 ofdm5ghpo;
805         u8 bw402gpo;
806         u8 bw405gpo;
807         u8 bw405glpo;
808         u8 bw405ghpo;
809         u8 cdd2gpo;
810         u8 cdd5gpo;
811         u8 cdd5glpo;
812         u8 cdd5ghpo;
813         u8 stbc2gpo;
814         u8 stbc5gpo;
815         u8 stbc5glpo;
816         u8 stbc5ghpo;
817         u8 bwdup2gpo;
818         u8 bwdup5gpo;
819         u8 bwdup5glpo;
820         u8 bwdup5ghpo;
821         u16 mcs2gpo[8];
822         u16 mcs5gpo[8];
823         u16 mcs5glpo[8];
824         u16 mcs5ghpo[8];
825         u32 nphy_rxcalparams;
826
827         u8 phy_spuravoid;
828         bool phy_isspuravoid;
829
830         u8 phy_pabias;
831         u8 nphy_papd_skip;
832         u8 nphy_tssi_slope;
833
834         s16 nphy_noise_win[PHY_CORE_MAX][PHY_NOISE_WINDOW_SZ];
835         u8 nphy_noise_index;
836
837         u8 nphy_txpid2g[PHY_CORE_NUM_2];
838         u8 nphy_txpid5g[PHY_CORE_NUM_2];
839         u8 nphy_txpid5gl[PHY_CORE_NUM_2];
840         u8 nphy_txpid5gh[PHY_CORE_NUM_2];
841
842         bool nphy_gain_boost;
843         bool nphy_elna_gain_config;
844         u16 old_bphy_test;
845         u16 old_bphy_testcontrol;
846
847         bool phyhang_avoid;
848
849         bool rssical_nphy;
850         u8 nphy_perical;
851         uint nphy_perical_last;
852         u8 cal_type_override;
853         u8 mphase_cal_phase_id;
854         u8 mphase_txcal_cmdidx;
855         u8 mphase_txcal_numcmds;
856         u16 mphase_txcal_bestcoeffs[11];
857         u16 nphy_txiqlocal_chanspec;
858         u16 nphy_iqcal_chanspec_2G;
859         u16 nphy_iqcal_chanspec_5G;
860         u16 nphy_rssical_chanspec_2G;
861         u16 nphy_rssical_chanspec_5G;
862         struct wlapi_timer *phycal_timer;
863         bool use_int_tx_iqlo_cal_nphy;
864         bool internal_tx_iqlo_cal_tapoff_intpa_nphy;
865         s16 nphy_lastcal_temp;
866
867         struct txiqcal_cache calibration_cache;
868         struct rssical_cache rssical_cache;
869
870         u8 nphy_txpwr_idx[2];
871         u8 nphy_papd_cal_type;
872         uint nphy_papd_last_cal;
873         u16 nphy_papd_tx_gain_at_last_cal[2];
874         u8 nphy_papd_cal_gain_index[2];
875         s16 nphy_papd_epsilon_offset[2];
876         bool nphy_papd_recal_enable;
877         u32 nphy_papd_recal_counter;
878         bool nphy_force_papd_cal;
879         bool nphy_papdcomp;
880         bool ipa2g_on;
881         bool ipa5g_on;
882
883         u16 classifier_state;
884         u16 clip_state[2];
885         uint nphy_deaf_count;
886         u8 rxiq_samps;
887         u8 rxiq_antsel;
888
889         u16 rfctrlIntc1_save;
890         u16 rfctrlIntc2_save;
891         bool first_cal_after_assoc;
892         u16 tx_rx_cal_radio_saveregs[22];
893         u16 tx_rx_cal_phy_saveregs[15];
894
895         u8 nphy_cal_orig_pwr_idx[2];
896         u8 nphy_txcal_pwr_idx[2];
897         u8 nphy_rxcal_pwr_idx[2];
898         u16 nphy_cal_orig_tx_gain[2];
899         struct nphy_txgains nphy_cal_target_gain;
900         u16 nphy_txcal_bbmult;
901         u16 nphy_gmval;
902
903         u16 nphy_saved_bbconf;
904
905         bool nphy_gband_spurwar_en;
906         bool nphy_gband_spurwar2_en;
907         bool nphy_aband_spurwar_en;
908         u16 nphy_rccal_value;
909         u16 nphy_crsminpwr[3];
910         struct nphy_noisevar_buf nphy_saved_noisevars;
911         bool nphy_anarxlpf_adjusted;
912         bool nphy_crsminpwr_adjusted;
913         bool nphy_noisevars_adjusted;
914
915         bool nphy_rxcal_active;
916         u16 radar_percal_mask;
917         bool dfs_lp_buffer_nphy;
918
919         u16 nphy_fineclockgatecontrol;
920
921         s8 rx2tx_biasentry;
922
923         u16 crsminpwr0;
924         u16 crsminpwrl0;
925         u16 crsminpwru0;
926         s16 noise_crsminpwr_index;
927         u16 init_gain_core1;
928         u16 init_gain_core2;
929         u16 init_gainb_core1;
930         u16 init_gainb_core2;
931         u8 aci_noise_curr_channel;
932         u16 init_gain_rfseq[4];
933
934         bool radio_is_on;
935
936         bool nphy_sample_play_lpf_bw_ctl_ovr;
937
938         u16 tbl_data_hi;
939         u16 tbl_data_lo;
940         u16 tbl_addr;
941
942         uint tbl_save_id;
943         uint tbl_save_offset;
944
945         u8 txpwrctrl;
946         s8 txpwrindex[PHY_CORE_MAX];
947
948         u8 phycal_tempdelta;
949         u32 mcs20_po;
950         u32 mcs40_po;
951         struct wiphy *wiphy;
952 };
953
954 struct cs32 {
955         s32 q;
956         s32 i;
957 };
958
959 struct radio_regs {
960         u16 address;
961         u32 init_a;
962         u32 init_g;
963         u8 do_init_a;
964         u8 do_init_g;
965 };
966
967 struct radio_20xx_regs {
968         u16 address;
969         u8 init;
970         u8 do_init;
971 };
972
973 struct lcnphy_radio_regs {
974         u16 address;
975         u8 init_a;
976         u8 init_g;
977         u8 do_init_a;
978         u8 do_init_g;
979 };
980
981 extern struct lcnphy_radio_regs lcnphy_radio_regs_2064[];
982 extern struct lcnphy_radio_regs lcnphy_radio_regs_2066[];
983
984 extern struct radio_regs regs_2055[], regs_SYN_2056[], regs_TX_2056[],
985                          regs_RX_2056[];
986 extern struct radio_regs regs_SYN_2056_A1[], regs_TX_2056_A1[],
987                          regs_RX_2056_A1[];
988 extern struct radio_regs regs_SYN_2056_rev5[], regs_TX_2056_rev5[],
989                          regs_RX_2056_rev5[];
990 extern struct radio_regs regs_SYN_2056_rev6[], regs_TX_2056_rev6[],
991                          regs_RX_2056_rev6[];
992 extern struct radio_regs regs_SYN_2056_rev7[], regs_TX_2056_rev7[],
993                          regs_RX_2056_rev7[];
994 extern struct radio_regs regs_SYN_2056_rev8[], regs_TX_2056_rev8[],
995                          regs_RX_2056_rev8[];
996
997 extern struct radio_20xx_regs regs_2057_rev4[], regs_2057_rev5[],
998                               regs_2057_rev5v1[];
999 extern struct radio_20xx_regs regs_2057_rev7[], regs_2057_rev8[];
1000
1001 extern char *phy_getvar(struct brcms_phy *pi, const char *name);
1002 extern int phy_getintvar(struct brcms_phy *pi, const char *name);
1003
1004 #define PHY_GETVAR(pi, name)    phy_getvar(pi, name)
1005 #define PHY_GETINTVAR(pi, name) phy_getintvar(pi, name)
1006
1007 extern u16 read_phy_reg(struct brcms_phy *pi, u16 addr);
1008 extern void write_phy_reg(struct brcms_phy *pi, u16 addr, u16 val);
1009 extern void and_phy_reg(struct brcms_phy *pi, u16 addr, u16 val);
1010 extern void or_phy_reg(struct brcms_phy *pi, u16 addr, u16 val);
1011 extern void mod_phy_reg(struct brcms_phy *pi, u16 addr, u16 mask, u16 val);
1012
1013 extern u16 read_radio_reg(struct brcms_phy *pi, u16 addr);
1014 extern void or_radio_reg(struct brcms_phy *pi, u16 addr, u16 val);
1015 extern void and_radio_reg(struct brcms_phy *pi, u16 addr, u16 val);
1016 extern void mod_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask,
1017                           u16 val);
1018 extern void xor_radio_reg(struct brcms_phy *pi, u16 addr, u16 mask);
1019
1020 extern void write_radio_reg(struct brcms_phy *pi, u16 addr, u16 val);
1021
1022 extern void wlc_phyreg_enter(struct brcms_phy_pub *pih);
1023 extern void wlc_phyreg_exit(struct brcms_phy_pub *pih);
1024 extern void wlc_radioreg_enter(struct brcms_phy_pub *pih);
1025 extern void wlc_radioreg_exit(struct brcms_phy_pub *pih);
1026
1027 extern void wlc_phy_read_table(struct brcms_phy *pi,
1028                                const struct phytbl_info *ptbl_info,
1029                                u16 tblAddr, u16 tblDataHi,
1030                                u16 tblDatalo);
1031 extern void wlc_phy_write_table(struct brcms_phy *pi,
1032                                 const struct phytbl_info *ptbl_info,
1033                                 u16 tblAddr, u16 tblDataHi, u16 tblDatalo);
1034 extern void wlc_phy_table_addr(struct brcms_phy *pi, uint tbl_id,
1035                                uint tbl_offset, u16 tblAddr, u16 tblDataHi,
1036                                u16 tblDataLo);
1037 extern void wlc_phy_table_data_write(struct brcms_phy *pi, uint width, u32 val);
1038
1039 extern void write_phy_channel_reg(struct brcms_phy *pi, uint val);
1040 extern void wlc_phy_txpower_update_shm(struct brcms_phy *pi);
1041
1042 extern void wlc_phy_cordic(s32 theta, struct cs32 *val);
1043 extern u8 wlc_phy_nbits(s32 value);
1044 extern void wlc_phy_compute_dB(u32 *cmplx_pwr, s8 *p_dB, u8 core);
1045
1046 extern uint wlc_phy_init_radio_regs_allbands(struct brcms_phy *pi,
1047                                              struct radio_20xx_regs *radioregs);
1048 extern uint wlc_phy_init_radio_regs(struct brcms_phy *pi,
1049                                     struct radio_regs *radioregs,
1050                                     u16 core_offset);
1051
1052 extern void wlc_phy_txpower_ipa_upd(struct brcms_phy *pi);
1053
1054 extern void wlc_phy_do_dummy_tx(struct brcms_phy *pi, bool ofdm, bool pa_on);
1055 extern void wlc_phy_papd_decode_epsilon(u32 epsilon, s32 *eps_real,
1056                                         s32 *eps_imag);
1057
1058 extern void wlc_phy_cal_perical_mphase_reset(struct brcms_phy *pi);
1059 extern void wlc_phy_cal_perical_mphase_restart(struct brcms_phy *pi);
1060
1061 extern bool wlc_phy_attach_nphy(struct brcms_phy *pi);
1062 extern bool wlc_phy_attach_lcnphy(struct brcms_phy *pi);
1063
1064 extern void wlc_phy_detach_lcnphy(struct brcms_phy *pi);
1065
1066 extern void wlc_phy_init_nphy(struct brcms_phy *pi);
1067 extern void wlc_phy_init_lcnphy(struct brcms_phy *pi);
1068
1069 extern void wlc_phy_cal_init_nphy(struct brcms_phy *pi);
1070 extern void wlc_phy_cal_init_lcnphy(struct brcms_phy *pi);
1071
1072 extern void wlc_phy_chanspec_set_nphy(struct brcms_phy *pi,
1073                                       u16 chanspec);
1074 extern void wlc_phy_chanspec_set_lcnphy(struct brcms_phy *pi,
1075                                         u16 chanspec);
1076 extern void wlc_phy_chanspec_set_fixup_lcnphy(struct brcms_phy *pi,
1077                                               u16 chanspec);
1078 extern int wlc_phy_channel2freq(uint channel);
1079 extern int wlc_phy_chanspec_freq2bandrange_lpssn(uint);
1080 extern int wlc_phy_chanspec_bandrange_get(struct brcms_phy *, u16 chanspec);
1081
1082 extern void wlc_lcnphy_set_tx_pwr_ctrl(struct brcms_phy *pi, u16 mode);
1083 extern s8 wlc_lcnphy_get_current_tx_pwr_idx(struct brcms_phy *pi);
1084
1085 extern void wlc_phy_txpower_recalc_target_nphy(struct brcms_phy *pi);
1086 extern void wlc_lcnphy_txpower_recalc_target(struct brcms_phy *pi);
1087 extern void wlc_phy_txpower_recalc_target_lcnphy(struct brcms_phy *pi);
1088
1089 extern void wlc_lcnphy_set_tx_pwr_by_index(struct brcms_phy *pi, int index);
1090 extern void wlc_lcnphy_tx_pu(struct brcms_phy *pi, bool bEnable);
1091 extern void wlc_lcnphy_stop_tx_tone(struct brcms_phy *pi);
1092 extern void wlc_lcnphy_start_tx_tone(struct brcms_phy *pi, s32 f_kHz,
1093                                      u16 max_val, bool iqcalmode);
1094
1095 extern void wlc_phy_txpower_sromlimit_get_nphy(struct brcms_phy *pi, uint chan,
1096                                                u8 *max_pwr, u8 rate_id);
1097 extern void wlc_phy_ofdm_to_mcs_powers_nphy(u8 *power, u8 rate_mcs_start,
1098                                             u8 rate_mcs_end,
1099                                             u8 rate_ofdm_start);
1100 extern void wlc_phy_mcs_to_ofdm_powers_nphy(u8 *power,
1101                                             u8 rate_ofdm_start,
1102                                             u8 rate_ofdm_end,
1103                                             u8 rate_mcs_start);
1104
1105 extern u16 wlc_lcnphy_tempsense(struct brcms_phy *pi, bool mode);
1106 extern s16 wlc_lcnphy_tempsense_new(struct brcms_phy *pi, bool mode);
1107 extern s8 wlc_lcnphy_tempsense_degree(struct brcms_phy *pi, bool mode);
1108 extern s8 wlc_lcnphy_vbatsense(struct brcms_phy *pi, bool mode);
1109 extern void wlc_phy_carrier_suppress_lcnphy(struct brcms_phy *pi);
1110 extern void wlc_lcnphy_crsuprs(struct brcms_phy *pi, int channel);
1111 extern void wlc_lcnphy_epa_switch(struct brcms_phy *pi, bool mode);
1112 extern void wlc_2064_vco_cal(struct brcms_phy *pi);
1113
1114 extern void wlc_phy_txpower_recalc_target(struct brcms_phy *pi);
1115
1116 #define LCNPHY_TBL_ID_PAPDCOMPDELTATBL  0x18
1117 #define LCNPHY_TX_POWER_TABLE_SIZE      128
1118 #define LCNPHY_MAX_TX_POWER_INDEX       (LCNPHY_TX_POWER_TABLE_SIZE - 1)
1119 #define LCNPHY_TBL_ID_TXPWRCTL  0x07
1120 #define LCNPHY_TX_PWR_CTRL_OFF  0
1121 #define LCNPHY_TX_PWR_CTRL_SW           (0x1 << 15)
1122 #define LCNPHY_TX_PWR_CTRL_HW         ((0x1 << 15) | \
1123                                         (0x1 << 14) | \
1124                                         (0x1 << 13))
1125
1126 #define LCNPHY_TX_PWR_CTRL_TEMPBASED    0xE001
1127
1128 extern void wlc_lcnphy_write_table(struct brcms_phy *pi,
1129                                    const struct phytbl_info *pti);
1130 extern void wlc_lcnphy_read_table(struct brcms_phy *pi,
1131                                   struct phytbl_info *pti);
1132 extern void wlc_lcnphy_set_tx_iqcc(struct brcms_phy *pi, u16 a, u16 b);
1133 extern void wlc_lcnphy_set_tx_locc(struct brcms_phy *pi, u16 didq);
1134 extern void wlc_lcnphy_get_tx_iqcc(struct brcms_phy *pi, u16 *a, u16 *b);
1135 extern u16 wlc_lcnphy_get_tx_locc(struct brcms_phy *pi);
1136 extern void wlc_lcnphy_get_radio_loft(struct brcms_phy *pi, u8 *ei0,
1137                                       u8 *eq0, u8 *fi0, u8 *fq0);
1138 extern void wlc_lcnphy_calib_modes(struct brcms_phy *pi, uint mode);
1139 extern void wlc_lcnphy_deaf_mode(struct brcms_phy *pi, bool mode);
1140 extern bool wlc_phy_tpc_isenabled_lcnphy(struct brcms_phy *pi);
1141 extern void wlc_lcnphy_tx_pwr_update_npt(struct brcms_phy *pi);
1142 extern s32 wlc_lcnphy_tssi2dbm(s32 tssi, s32 a1, s32 b0, s32 b1);
1143 extern void wlc_lcnphy_get_tssi(struct brcms_phy *pi, s8 *ofdm_pwr,
1144                                 s8 *cck_pwr);
1145 extern void wlc_lcnphy_tx_power_adjustment(struct brcms_phy_pub *ppi);
1146
1147 extern s32 wlc_lcnphy_rx_signal_power(struct brcms_phy *pi, s32 gain_index);
1148
1149 #define NPHY_MAX_HPVGA1_INDEX           10
1150 #define NPHY_DEF_HPVGA1_INDEXLIMIT      7
1151
1152 struct phy_iq_est {
1153         s32 iq_prod;
1154         u32 i_pwr;
1155         u32 q_pwr;
1156 };
1157
1158 extern void wlc_phy_stay_in_carriersearch_nphy(struct brcms_phy *pi,
1159                                                bool enable);
1160 extern void wlc_nphy_deaf_mode(struct brcms_phy *pi, bool mode);
1161
1162 #define wlc_phy_write_table_nphy(pi, pti) \
1163         wlc_phy_write_table(pi, pti, 0x72, 0x74, 0x73)
1164
1165 #define wlc_phy_read_table_nphy(pi, pti) \
1166         wlc_phy_read_table(pi, pti, 0x72, 0x74, 0x73)
1167
1168 #define wlc_nphy_table_addr(pi, id, off) \
1169         wlc_phy_table_addr((pi), (id), (off), 0x72, 0x74, 0x73)
1170
1171 #define wlc_nphy_table_data_write(pi, w, v) \
1172         wlc_phy_table_data_write((pi), (w), (v))
1173
1174 extern void wlc_phy_table_read_nphy(struct brcms_phy *pi, u32, u32 l, u32 o,
1175                                     u32 w, void *d);
1176 extern void wlc_phy_table_write_nphy(struct brcms_phy *pi, u32, u32, u32,
1177                                      u32, const void *);
1178
1179 #define PHY_IPA(pi) \
1180         ((pi->ipa2g_on && CHSPEC_IS2G(pi->radio_chanspec)) || \
1181          (pi->ipa5g_on && CHSPEC_IS5G(pi->radio_chanspec)))
1182
1183 #define BRCMS_PHY_WAR_PR51571(pi) \
1184         if (((pi)->sh->bustype == PCI_BUS) && NREV_LT((pi)->pubpi.phy_rev, 3)) \
1185                 (void)R_REG(&(pi)->regs->maccontrol)
1186
1187 extern void wlc_phy_cal_perical_nphy_run(struct brcms_phy *pi, u8 caltype);
1188 extern void wlc_phy_aci_reset_nphy(struct brcms_phy *pi);
1189 extern void wlc_phy_pa_override_nphy(struct brcms_phy *pi, bool en);
1190
1191 extern u8 wlc_phy_get_chan_freq_range_nphy(struct brcms_phy *pi, uint chan);
1192 extern void wlc_phy_switch_radio_nphy(struct brcms_phy *pi, bool on);
1193
1194 extern void wlc_phy_stf_chain_upd_nphy(struct brcms_phy *pi);
1195
1196 extern void wlc_phy_force_rfseq_nphy(struct brcms_phy *pi, u8 cmd);
1197 extern s16 wlc_phy_tempsense_nphy(struct brcms_phy *pi);
1198
1199 extern u16 wlc_phy_classifier_nphy(struct brcms_phy *pi, u16 mask, u16 val);
1200
1201 extern void wlc_phy_rx_iq_est_nphy(struct brcms_phy *pi, struct phy_iq_est *est,
1202                                    u16 num_samps, u8 wait_time,
1203                                    u8 wait_for_crs);
1204
1205 extern void wlc_phy_rx_iq_coeffs_nphy(struct brcms_phy *pi, u8 write,
1206                                       struct nphy_iq_comp *comp);
1207 extern void wlc_phy_aci_and_noise_reduction_nphy(struct brcms_phy *pi);
1208
1209 extern void wlc_phy_rxcore_setstate_nphy(struct brcms_phy_pub *pih,
1210                                          u8 rxcore_bitmask);
1211 extern u8 wlc_phy_rxcore_getstate_nphy(struct brcms_phy_pub *pih);
1212
1213 extern void wlc_phy_txpwrctrl_enable_nphy(struct brcms_phy *pi, u8 ctrl_type);
1214 extern void wlc_phy_txpwr_fixpower_nphy(struct brcms_phy *pi);
1215 extern void wlc_phy_txpwr_apply_nphy(struct brcms_phy *pi);
1216 extern void wlc_phy_txpwr_papd_cal_nphy(struct brcms_phy *pi);
1217 extern u16 wlc_phy_txpwr_idx_get_nphy(struct brcms_phy *pi);
1218
1219 extern struct nphy_txgains wlc_phy_get_tx_gain_nphy(struct brcms_phy *pi);
1220 extern int wlc_phy_cal_txiqlo_nphy(struct brcms_phy *pi,
1221                                    struct nphy_txgains target_gain,
1222                                    bool full, bool m);
1223 extern int wlc_phy_cal_rxiq_nphy(struct brcms_phy *pi,
1224                                  struct nphy_txgains target_gain,
1225                                  u8 type, bool d);
1226 extern void wlc_phy_txpwr_index_nphy(struct brcms_phy *pi, u8 core_mask,
1227                                      s8 txpwrindex, bool res);
1228 extern void wlc_phy_rssisel_nphy(struct brcms_phy *pi, u8 core, u8 rssi_type);
1229 extern int wlc_phy_poll_rssi_nphy(struct brcms_phy *pi, u8 rssi_type,
1230                                   s32 *rssi_buf, u8 nsamps);
1231 extern void wlc_phy_rssi_cal_nphy(struct brcms_phy *pi);
1232 extern int wlc_phy_aci_scan_nphy(struct brcms_phy *pi);
1233 extern void wlc_phy_cal_txgainctrl_nphy(struct brcms_phy *pi,
1234                                         s32 dBm_targetpower, bool debug);
1235 extern int wlc_phy_tx_tone_nphy(struct brcms_phy *pi, u32 f_kHz, u16 max_val,
1236                                 u8 mode, u8, bool);
1237 extern void wlc_phy_stopplayback_nphy(struct brcms_phy *pi);
1238 extern void wlc_phy_est_tonepwr_nphy(struct brcms_phy *pi, s32 *qdBm_pwrbuf,
1239                                      u8 num_samps);
1240 extern void wlc_phy_radio205x_vcocal_nphy(struct brcms_phy *pi);
1241
1242 extern int wlc_phy_rssi_compute_nphy(struct brcms_phy *pi,
1243                                      struct brcms_d11rxhdr *wlc_rxh);
1244
1245 #define NPHY_TESTPATTERN_BPHY_EVM   0
1246 #define NPHY_TESTPATTERN_BPHY_RFCS  1
1247
1248 extern void wlc_phy_nphy_tkip_rifs_war(struct brcms_phy *pi, u8 rifs);
1249
1250 void wlc_phy_get_pwrdet_offsets(struct brcms_phy *pi, s8 *cckoffset,
1251                                 s8 *ofdmoffset);
1252 extern s8 wlc_phy_upd_rssi_offset(struct brcms_phy *pi, s8 rssi,
1253                                   u16 chanspec);
1254
1255 extern bool wlc_phy_n_txpower_ipa_ison(struct brcms_phy *pih);
1256 #endif                          /* _BRCM_PHY_INT_H_ */