1*b4c3e9b5SBjoern A. Zeeb /*
2*b4c3e9b5SBjoern A. Zeeb * Copyright (c) 2010 Broadcom Corporation
3*b4c3e9b5SBjoern A. Zeeb *
4*b4c3e9b5SBjoern A. Zeeb * Permission to use, copy, modify, and/or distribute this software for any
5*b4c3e9b5SBjoern A. Zeeb * purpose with or without fee is hereby granted, provided that the above
6*b4c3e9b5SBjoern A. Zeeb * copyright notice and this permission notice appear in all copies.
7*b4c3e9b5SBjoern A. Zeeb *
8*b4c3e9b5SBjoern A. Zeeb * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*b4c3e9b5SBjoern A. Zeeb * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*b4c3e9b5SBjoern A. Zeeb * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11*b4c3e9b5SBjoern A. Zeeb * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*b4c3e9b5SBjoern A. Zeeb * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13*b4c3e9b5SBjoern A. Zeeb * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14*b4c3e9b5SBjoern A. Zeeb * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*b4c3e9b5SBjoern A. Zeeb */
16*b4c3e9b5SBjoern A. Zeeb
17*b4c3e9b5SBjoern A. Zeeb #include <linux/slab.h>
18*b4c3e9b5SBjoern A. Zeeb #include <net/mac80211.h>
19*b4c3e9b5SBjoern A. Zeeb
20*b4c3e9b5SBjoern A. Zeeb #include "types.h"
21*b4c3e9b5SBjoern A. Zeeb #include "main.h"
22*b4c3e9b5SBjoern A. Zeeb #include "phy_shim.h"
23*b4c3e9b5SBjoern A. Zeeb #include "antsel.h"
24*b4c3e9b5SBjoern A. Zeeb #include "debug.h"
25*b4c3e9b5SBjoern A. Zeeb
26*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_AUTO 0x80 /* bit indicates antenna sel AUTO */
27*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_MASK 0x33 /* antenna configuration mask */
28*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_TX_UNICAST 0 /* unicast tx antenna configuration */
29*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_RX_UNICAST 1 /* unicast rx antenna configuration */
30*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_TX_DEF 2 /* default tx antenna configuration */
31*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_RX_DEF 3 /* default rx antenna configuration */
32*b4c3e9b5SBjoern A. Zeeb
33*b4c3e9b5SBjoern A. Zeeb /* useful macros */
34*b4c3e9b5SBjoern A. Zeeb #define BRCMS_ANTSEL_11N_0(ant) ((((ant) & ANT_SELCFG_MASK) >> 4) & 0xf)
35*b4c3e9b5SBjoern A. Zeeb #define BRCMS_ANTSEL_11N_1(ant) (((ant) & ANT_SELCFG_MASK) & 0xf)
36*b4c3e9b5SBjoern A. Zeeb #define BRCMS_ANTIDX_11N(ant) (((BRCMS_ANTSEL_11N_0(ant)) << 2) +\
37*b4c3e9b5SBjoern A. Zeeb (BRCMS_ANTSEL_11N_1(ant)))
38*b4c3e9b5SBjoern A. Zeeb #define BRCMS_ANT_ISAUTO_11N(ant) (((ant) & ANT_SELCFG_AUTO) == ANT_SELCFG_AUTO)
39*b4c3e9b5SBjoern A. Zeeb #define BRCMS_ANTSEL_11N(ant) ((ant) & ANT_SELCFG_MASK)
40*b4c3e9b5SBjoern A. Zeeb
41*b4c3e9b5SBjoern A. Zeeb /* antenna switch */
42*b4c3e9b5SBjoern A. Zeeb /* defines for no boardlevel antenna diversity */
43*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_DEF_2x2 0x01 /* default antenna configuration */
44*b4c3e9b5SBjoern A. Zeeb
45*b4c3e9b5SBjoern A. Zeeb /* 2x3 antdiv defines and tables for GPIO communication */
46*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_NUM_2x3 3
47*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_DEF_2x3 0x01 /* default antenna configuration */
48*b4c3e9b5SBjoern A. Zeeb
49*b4c3e9b5SBjoern A. Zeeb /* 2x4 antdiv rev4 defines and tables for GPIO communication */
50*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_NUM_2x4 4
51*b4c3e9b5SBjoern A. Zeeb #define ANT_SELCFG_DEF_2x4 0x02 /* default antenna configuration */
52*b4c3e9b5SBjoern A. Zeeb
53*b4c3e9b5SBjoern A. Zeeb static const u16 mimo_2x4_div_antselpat_tbl[] = {
54*b4c3e9b5SBjoern A. Zeeb 0, 0, 0x9, 0xa, /* ant0: 0 ant1: 2,3 */
55*b4c3e9b5SBjoern A. Zeeb 0, 0, 0x5, 0x6, /* ant0: 1 ant1: 2,3 */
56*b4c3e9b5SBjoern A. Zeeb 0, 0, 0, 0, /* n.a. */
57*b4c3e9b5SBjoern A. Zeeb 0, 0, 0, 0 /* n.a. */
58*b4c3e9b5SBjoern A. Zeeb };
59*b4c3e9b5SBjoern A. Zeeb
60*b4c3e9b5SBjoern A. Zeeb static const u8 mimo_2x4_div_antselid_tbl[16] = {
61*b4c3e9b5SBjoern A. Zeeb 0, 0, 0, 0, 0, 2, 3, 0,
62*b4c3e9b5SBjoern A. Zeeb 0, 0, 1, 0, 0, 0, 0, 0 /* pat to antselid */
63*b4c3e9b5SBjoern A. Zeeb };
64*b4c3e9b5SBjoern A. Zeeb
65*b4c3e9b5SBjoern A. Zeeb static const u16 mimo_2x3_div_antselpat_tbl[] = {
66*b4c3e9b5SBjoern A. Zeeb 16, 0, 1, 16, /* ant0: 0 ant1: 1,2 */
67*b4c3e9b5SBjoern A. Zeeb 16, 16, 16, 16, /* n.a. */
68*b4c3e9b5SBjoern A. Zeeb 16, 2, 16, 16, /* ant0: 2 ant1: 1 */
69*b4c3e9b5SBjoern A. Zeeb 16, 16, 16, 16 /* n.a. */
70*b4c3e9b5SBjoern A. Zeeb };
71*b4c3e9b5SBjoern A. Zeeb
72*b4c3e9b5SBjoern A. Zeeb static const u8 mimo_2x3_div_antselid_tbl[16] = {
73*b4c3e9b5SBjoern A. Zeeb 0, 1, 2, 0, 0, 0, 0, 0,
74*b4c3e9b5SBjoern A. Zeeb 0, 0, 0, 0, 0, 0, 0, 0 /* pat to antselid */
75*b4c3e9b5SBjoern A. Zeeb };
76*b4c3e9b5SBjoern A. Zeeb
77*b4c3e9b5SBjoern A. Zeeb /* boardlevel antenna selection: init antenna selection structure */
78*b4c3e9b5SBjoern A. Zeeb static void
brcms_c_antsel_init_cfg(struct antsel_info * asi,struct brcms_antselcfg * antsel,bool auto_sel)79*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_init_cfg(struct antsel_info *asi, struct brcms_antselcfg *antsel,
80*b4c3e9b5SBjoern A. Zeeb bool auto_sel)
81*b4c3e9b5SBjoern A. Zeeb {
82*b4c3e9b5SBjoern A. Zeeb if (asi->antsel_type == ANTSEL_2x3) {
83*b4c3e9b5SBjoern A. Zeeb u8 antcfg_def = ANT_SELCFG_DEF_2x3 |
84*b4c3e9b5SBjoern A. Zeeb ((asi->antsel_avail && auto_sel) ? ANT_SELCFG_AUTO : 0);
85*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_DEF] = antcfg_def;
86*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_UNICAST] = antcfg_def;
87*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_DEF] = antcfg_def;
88*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_UNICAST] = antcfg_def;
89*b4c3e9b5SBjoern A. Zeeb antsel->num_antcfg = ANT_SELCFG_NUM_2x3;
90*b4c3e9b5SBjoern A. Zeeb
91*b4c3e9b5SBjoern A. Zeeb } else if (asi->antsel_type == ANTSEL_2x4) {
92*b4c3e9b5SBjoern A. Zeeb
93*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_DEF] = ANT_SELCFG_DEF_2x4;
94*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_UNICAST] = ANT_SELCFG_DEF_2x4;
95*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_DEF] = ANT_SELCFG_DEF_2x4;
96*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_UNICAST] = ANT_SELCFG_DEF_2x4;
97*b4c3e9b5SBjoern A. Zeeb antsel->num_antcfg = ANT_SELCFG_NUM_2x4;
98*b4c3e9b5SBjoern A. Zeeb
99*b4c3e9b5SBjoern A. Zeeb } else { /* no antenna selection available */
100*b4c3e9b5SBjoern A. Zeeb
101*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_DEF] = ANT_SELCFG_DEF_2x2;
102*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_TX_UNICAST] = ANT_SELCFG_DEF_2x2;
103*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_DEF] = ANT_SELCFG_DEF_2x2;
104*b4c3e9b5SBjoern A. Zeeb antsel->ant_config[ANT_SELCFG_RX_UNICAST] = ANT_SELCFG_DEF_2x2;
105*b4c3e9b5SBjoern A. Zeeb antsel->num_antcfg = 0;
106*b4c3e9b5SBjoern A. Zeeb }
107*b4c3e9b5SBjoern A. Zeeb }
108*b4c3e9b5SBjoern A. Zeeb
brcms_c_antsel_attach(struct brcms_c_info * wlc)109*b4c3e9b5SBjoern A. Zeeb struct antsel_info *brcms_c_antsel_attach(struct brcms_c_info *wlc)
110*b4c3e9b5SBjoern A. Zeeb {
111*b4c3e9b5SBjoern A. Zeeb struct antsel_info *asi;
112*b4c3e9b5SBjoern A. Zeeb struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
113*b4c3e9b5SBjoern A. Zeeb
114*b4c3e9b5SBjoern A. Zeeb asi = kzalloc(sizeof(*asi), GFP_ATOMIC);
115*b4c3e9b5SBjoern A. Zeeb if (!asi)
116*b4c3e9b5SBjoern A. Zeeb return NULL;
117*b4c3e9b5SBjoern A. Zeeb
118*b4c3e9b5SBjoern A. Zeeb asi->wlc = wlc;
119*b4c3e9b5SBjoern A. Zeeb asi->pub = wlc->pub;
120*b4c3e9b5SBjoern A. Zeeb asi->antsel_type = ANTSEL_NA;
121*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = false;
122*b4c3e9b5SBjoern A. Zeeb asi->antsel_antswitch = sprom->antswitch;
123*b4c3e9b5SBjoern A. Zeeb
124*b4c3e9b5SBjoern A. Zeeb if ((asi->pub->sromrev >= 4) && (asi->antsel_antswitch != 0)) {
125*b4c3e9b5SBjoern A. Zeeb switch (asi->antsel_antswitch) {
126*b4c3e9b5SBjoern A. Zeeb case ANTSWITCH_TYPE_1:
127*b4c3e9b5SBjoern A. Zeeb case ANTSWITCH_TYPE_2:
128*b4c3e9b5SBjoern A. Zeeb case ANTSWITCH_TYPE_3:
129*b4c3e9b5SBjoern A. Zeeb /* 4321/2 board with 2x3 switch logic */
130*b4c3e9b5SBjoern A. Zeeb asi->antsel_type = ANTSEL_2x3;
131*b4c3e9b5SBjoern A. Zeeb /* Antenna selection availability */
132*b4c3e9b5SBjoern A. Zeeb if ((sprom->ant_available_bg == 7) ||
133*b4c3e9b5SBjoern A. Zeeb (sprom->ant_available_a == 7)) {
134*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = true;
135*b4c3e9b5SBjoern A. Zeeb } else if (
136*b4c3e9b5SBjoern A. Zeeb sprom->ant_available_bg == 3 ||
137*b4c3e9b5SBjoern A. Zeeb sprom->ant_available_a == 3) {
138*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = false;
139*b4c3e9b5SBjoern A. Zeeb } else {
140*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = false;
141*b4c3e9b5SBjoern A. Zeeb brcms_err(wlc->hw->d11core,
142*b4c3e9b5SBjoern A. Zeeb "antsel_attach: 2o3 "
143*b4c3e9b5SBjoern A. Zeeb "board cfg invalid\n");
144*b4c3e9b5SBjoern A. Zeeb }
145*b4c3e9b5SBjoern A. Zeeb
146*b4c3e9b5SBjoern A. Zeeb break;
147*b4c3e9b5SBjoern A. Zeeb default:
148*b4c3e9b5SBjoern A. Zeeb break;
149*b4c3e9b5SBjoern A. Zeeb }
150*b4c3e9b5SBjoern A. Zeeb } else if ((asi->pub->sromrev == 4) &&
151*b4c3e9b5SBjoern A. Zeeb (sprom->ant_available_bg == 7) &&
152*b4c3e9b5SBjoern A. Zeeb (sprom->ant_available_a == 0)) {
153*b4c3e9b5SBjoern A. Zeeb /* hack to match old 4321CB2 cards with 2of3 antenna switch */
154*b4c3e9b5SBjoern A. Zeeb asi->antsel_type = ANTSEL_2x3;
155*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = true;
156*b4c3e9b5SBjoern A. Zeeb } else if (asi->pub->boardflags2 & BFL2_2X4_DIV) {
157*b4c3e9b5SBjoern A. Zeeb asi->antsel_type = ANTSEL_2x4;
158*b4c3e9b5SBjoern A. Zeeb asi->antsel_avail = true;
159*b4c3e9b5SBjoern A. Zeeb }
160*b4c3e9b5SBjoern A. Zeeb
161*b4c3e9b5SBjoern A. Zeeb /* Set the antenna selection type for the low driver */
162*b4c3e9b5SBjoern A. Zeeb brcms_b_antsel_type_set(wlc->hw, asi->antsel_type);
163*b4c3e9b5SBjoern A. Zeeb
164*b4c3e9b5SBjoern A. Zeeb /* Init (auto/manual) antenna selection */
165*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_init_cfg(asi, &asi->antcfg_11n, true);
166*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_init_cfg(asi, &asi->antcfg_cur, true);
167*b4c3e9b5SBjoern A. Zeeb
168*b4c3e9b5SBjoern A. Zeeb return asi;
169*b4c3e9b5SBjoern A. Zeeb }
170*b4c3e9b5SBjoern A. Zeeb
brcms_c_antsel_detach(struct antsel_info * asi)171*b4c3e9b5SBjoern A. Zeeb void brcms_c_antsel_detach(struct antsel_info *asi)
172*b4c3e9b5SBjoern A. Zeeb {
173*b4c3e9b5SBjoern A. Zeeb kfree(asi);
174*b4c3e9b5SBjoern A. Zeeb }
175*b4c3e9b5SBjoern A. Zeeb
176*b4c3e9b5SBjoern A. Zeeb /*
177*b4c3e9b5SBjoern A. Zeeb * boardlevel antenna selection:
178*b4c3e9b5SBjoern A. Zeeb * convert ant_cfg to mimo_antsel (ucode interface)
179*b4c3e9b5SBjoern A. Zeeb */
brcms_c_antsel_antcfg2antsel(struct antsel_info * asi,u8 ant_cfg)180*b4c3e9b5SBjoern A. Zeeb static u16 brcms_c_antsel_antcfg2antsel(struct antsel_info *asi, u8 ant_cfg)
181*b4c3e9b5SBjoern A. Zeeb {
182*b4c3e9b5SBjoern A. Zeeb u8 idx = BRCMS_ANTIDX_11N(BRCMS_ANTSEL_11N(ant_cfg));
183*b4c3e9b5SBjoern A. Zeeb u16 mimo_antsel = 0;
184*b4c3e9b5SBjoern A. Zeeb
185*b4c3e9b5SBjoern A. Zeeb if (asi->antsel_type == ANTSEL_2x4) {
186*b4c3e9b5SBjoern A. Zeeb /* 2x4 antenna diversity board, 4 cfgs: 0-2 0-3 1-2 1-3 */
187*b4c3e9b5SBjoern A. Zeeb mimo_antsel = (mimo_2x4_div_antselpat_tbl[idx] & 0xf);
188*b4c3e9b5SBjoern A. Zeeb return mimo_antsel;
189*b4c3e9b5SBjoern A. Zeeb
190*b4c3e9b5SBjoern A. Zeeb } else if (asi->antsel_type == ANTSEL_2x3) {
191*b4c3e9b5SBjoern A. Zeeb /* 2x3 antenna selection, 3 cfgs: 0-1 0-2 2-1 */
192*b4c3e9b5SBjoern A. Zeeb mimo_antsel = (mimo_2x3_div_antselpat_tbl[idx] & 0xf);
193*b4c3e9b5SBjoern A. Zeeb return mimo_antsel;
194*b4c3e9b5SBjoern A. Zeeb }
195*b4c3e9b5SBjoern A. Zeeb
196*b4c3e9b5SBjoern A. Zeeb return mimo_antsel;
197*b4c3e9b5SBjoern A. Zeeb }
198*b4c3e9b5SBjoern A. Zeeb
199*b4c3e9b5SBjoern A. Zeeb /* boardlevel antenna selection: ucode interface control */
brcms_c_antsel_cfgupd(struct antsel_info * asi,struct brcms_antselcfg * antsel)200*b4c3e9b5SBjoern A. Zeeb static int brcms_c_antsel_cfgupd(struct antsel_info *asi,
201*b4c3e9b5SBjoern A. Zeeb struct brcms_antselcfg *antsel)
202*b4c3e9b5SBjoern A. Zeeb {
203*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = asi->wlc;
204*b4c3e9b5SBjoern A. Zeeb u8 ant_cfg;
205*b4c3e9b5SBjoern A. Zeeb u16 mimo_antsel;
206*b4c3e9b5SBjoern A. Zeeb
207*b4c3e9b5SBjoern A. Zeeb /* 1) Update TX antconfig for all frames that are not unicast data
208*b4c3e9b5SBjoern A. Zeeb * (aka default TX)
209*b4c3e9b5SBjoern A. Zeeb */
210*b4c3e9b5SBjoern A. Zeeb ant_cfg = antsel->ant_config[ANT_SELCFG_TX_DEF];
211*b4c3e9b5SBjoern A. Zeeb mimo_antsel = brcms_c_antsel_antcfg2antsel(asi, ant_cfg);
212*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_MIMO_ANTSEL_TXDFLT, mimo_antsel);
213*b4c3e9b5SBjoern A. Zeeb /*
214*b4c3e9b5SBjoern A. Zeeb * Update driver stats for currently selected
215*b4c3e9b5SBjoern A. Zeeb * default tx/rx antenna config
216*b4c3e9b5SBjoern A. Zeeb */
217*b4c3e9b5SBjoern A. Zeeb asi->antcfg_cur.ant_config[ANT_SELCFG_TX_DEF] = ant_cfg;
218*b4c3e9b5SBjoern A. Zeeb
219*b4c3e9b5SBjoern A. Zeeb /* 2) Update RX antconfig for all frames that are not unicast data
220*b4c3e9b5SBjoern A. Zeeb * (aka default RX)
221*b4c3e9b5SBjoern A. Zeeb */
222*b4c3e9b5SBjoern A. Zeeb ant_cfg = antsel->ant_config[ANT_SELCFG_RX_DEF];
223*b4c3e9b5SBjoern A. Zeeb mimo_antsel = brcms_c_antsel_antcfg2antsel(asi, ant_cfg);
224*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_MIMO_ANTSEL_RXDFLT, mimo_antsel);
225*b4c3e9b5SBjoern A. Zeeb /*
226*b4c3e9b5SBjoern A. Zeeb * Update driver stats for currently selected
227*b4c3e9b5SBjoern A. Zeeb * default tx/rx antenna config
228*b4c3e9b5SBjoern A. Zeeb */
229*b4c3e9b5SBjoern A. Zeeb asi->antcfg_cur.ant_config[ANT_SELCFG_RX_DEF] = ant_cfg;
230*b4c3e9b5SBjoern A. Zeeb
231*b4c3e9b5SBjoern A. Zeeb return 0;
232*b4c3e9b5SBjoern A. Zeeb }
233*b4c3e9b5SBjoern A. Zeeb
brcms_c_antsel_init(struct antsel_info * asi)234*b4c3e9b5SBjoern A. Zeeb void brcms_c_antsel_init(struct antsel_info *asi)
235*b4c3e9b5SBjoern A. Zeeb {
236*b4c3e9b5SBjoern A. Zeeb if ((asi->antsel_type == ANTSEL_2x3) ||
237*b4c3e9b5SBjoern A. Zeeb (asi->antsel_type == ANTSEL_2x4))
238*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_cfgupd(asi, &asi->antcfg_11n);
239*b4c3e9b5SBjoern A. Zeeb }
240*b4c3e9b5SBjoern A. Zeeb
241*b4c3e9b5SBjoern A. Zeeb /* boardlevel antenna selection: convert id to ant_cfg */
brcms_c_antsel_id2antcfg(struct antsel_info * asi,u8 id)242*b4c3e9b5SBjoern A. Zeeb static u8 brcms_c_antsel_id2antcfg(struct antsel_info *asi, u8 id)
243*b4c3e9b5SBjoern A. Zeeb {
244*b4c3e9b5SBjoern A. Zeeb u8 antcfg = ANT_SELCFG_DEF_2x2;
245*b4c3e9b5SBjoern A. Zeeb
246*b4c3e9b5SBjoern A. Zeeb if (asi->antsel_type == ANTSEL_2x4) {
247*b4c3e9b5SBjoern A. Zeeb /* 2x4 antenna diversity board, 4 cfgs: 0-2 0-3 1-2 1-3 */
248*b4c3e9b5SBjoern A. Zeeb antcfg = (((id & 0x2) << 3) | ((id & 0x1) + 2));
249*b4c3e9b5SBjoern A. Zeeb return antcfg;
250*b4c3e9b5SBjoern A. Zeeb
251*b4c3e9b5SBjoern A. Zeeb } else if (asi->antsel_type == ANTSEL_2x3) {
252*b4c3e9b5SBjoern A. Zeeb /* 2x3 antenna selection, 3 cfgs: 0-1 0-2 2-1 */
253*b4c3e9b5SBjoern A. Zeeb antcfg = (((id & 0x02) << 4) | ((id & 0x1) + 1));
254*b4c3e9b5SBjoern A. Zeeb return antcfg;
255*b4c3e9b5SBjoern A. Zeeb }
256*b4c3e9b5SBjoern A. Zeeb
257*b4c3e9b5SBjoern A. Zeeb return antcfg;
258*b4c3e9b5SBjoern A. Zeeb }
259*b4c3e9b5SBjoern A. Zeeb
260*b4c3e9b5SBjoern A. Zeeb void
brcms_c_antsel_antcfg_get(struct antsel_info * asi,bool usedef,bool sel,u8 antselid,u8 fbantselid,u8 * antcfg,u8 * fbantcfg)261*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_antcfg_get(struct antsel_info *asi, bool usedef, bool sel,
262*b4c3e9b5SBjoern A. Zeeb u8 antselid, u8 fbantselid, u8 *antcfg,
263*b4c3e9b5SBjoern A. Zeeb u8 *fbantcfg)
264*b4c3e9b5SBjoern A. Zeeb {
265*b4c3e9b5SBjoern A. Zeeb u8 ant;
266*b4c3e9b5SBjoern A. Zeeb
267*b4c3e9b5SBjoern A. Zeeb /* if use default, assign it and return */
268*b4c3e9b5SBjoern A. Zeeb if (usedef) {
269*b4c3e9b5SBjoern A. Zeeb *antcfg = asi->antcfg_11n.ant_config[ANT_SELCFG_TX_DEF];
270*b4c3e9b5SBjoern A. Zeeb *fbantcfg = *antcfg;
271*b4c3e9b5SBjoern A. Zeeb return;
272*b4c3e9b5SBjoern A. Zeeb }
273*b4c3e9b5SBjoern A. Zeeb
274*b4c3e9b5SBjoern A. Zeeb if (!sel) {
275*b4c3e9b5SBjoern A. Zeeb *antcfg = asi->antcfg_11n.ant_config[ANT_SELCFG_TX_UNICAST];
276*b4c3e9b5SBjoern A. Zeeb *fbantcfg = *antcfg;
277*b4c3e9b5SBjoern A. Zeeb
278*b4c3e9b5SBjoern A. Zeeb } else {
279*b4c3e9b5SBjoern A. Zeeb ant = asi->antcfg_11n.ant_config[ANT_SELCFG_TX_UNICAST];
280*b4c3e9b5SBjoern A. Zeeb if ((ant & ANT_SELCFG_AUTO) == ANT_SELCFG_AUTO) {
281*b4c3e9b5SBjoern A. Zeeb *antcfg = brcms_c_antsel_id2antcfg(asi, antselid);
282*b4c3e9b5SBjoern A. Zeeb *fbantcfg = brcms_c_antsel_id2antcfg(asi, fbantselid);
283*b4c3e9b5SBjoern A. Zeeb } else {
284*b4c3e9b5SBjoern A. Zeeb *antcfg =
285*b4c3e9b5SBjoern A. Zeeb asi->antcfg_11n.ant_config[ANT_SELCFG_TX_UNICAST];
286*b4c3e9b5SBjoern A. Zeeb *fbantcfg = *antcfg;
287*b4c3e9b5SBjoern A. Zeeb }
288*b4c3e9b5SBjoern A. Zeeb }
289*b4c3e9b5SBjoern A. Zeeb return;
290*b4c3e9b5SBjoern A. Zeeb }
291*b4c3e9b5SBjoern A. Zeeb
292*b4c3e9b5SBjoern A. Zeeb /* boardlevel antenna selection: convert mimo_antsel (ucode interface) to id */
brcms_c_antsel_antsel2id(struct antsel_info * asi,u16 antsel)293*b4c3e9b5SBjoern A. Zeeb u8 brcms_c_antsel_antsel2id(struct antsel_info *asi, u16 antsel)
294*b4c3e9b5SBjoern A. Zeeb {
295*b4c3e9b5SBjoern A. Zeeb u8 antselid = 0;
296*b4c3e9b5SBjoern A. Zeeb
297*b4c3e9b5SBjoern A. Zeeb if (asi->antsel_type == ANTSEL_2x4) {
298*b4c3e9b5SBjoern A. Zeeb /* 2x4 antenna diversity board, 4 cfgs: 0-2 0-3 1-2 1-3 */
299*b4c3e9b5SBjoern A. Zeeb antselid = mimo_2x4_div_antselid_tbl[(antsel & 0xf)];
300*b4c3e9b5SBjoern A. Zeeb return antselid;
301*b4c3e9b5SBjoern A. Zeeb
302*b4c3e9b5SBjoern A. Zeeb } else if (asi->antsel_type == ANTSEL_2x3) {
303*b4c3e9b5SBjoern A. Zeeb /* 2x3 antenna selection, 3 cfgs: 0-1 0-2 2-1 */
304*b4c3e9b5SBjoern A. Zeeb antselid = mimo_2x3_div_antselid_tbl[(antsel & 0xf)];
305*b4c3e9b5SBjoern A. Zeeb return antselid;
306*b4c3e9b5SBjoern A. Zeeb }
307*b4c3e9b5SBjoern A. Zeeb
308*b4c3e9b5SBjoern A. Zeeb return antselid;
309*b4c3e9b5SBjoern A. Zeeb }
310