SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-19 2e7235d10c6dbff81960282e1a1e2e798f9b8db8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "mp_precomp.h"
 
static struct    rfe_type_8821c_wifi_only    gl_rfe_type_8821c_1ant;
static struct    rfe_type_8821c_wifi_only    *rfe_type = &gl_rfe_type_8821c_1ant;
 
 
 
VOID hal8821c_wifi_only_switch_antenna(
    IN struct wifi_only_cfg *pwifionlycfg,
    IN u1Byte is_5g
    )
{
    boolean switch_polatiry_inverse = false;
    u8    regval_0xcb7 = 0;
    u8    pos_type, ctrl_type;
 
    if (!rfe_type->ext_ant_switch_exist)
        return;
 
    /* swap control polarity if use different switch control polarity*/
    /*    Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux,  0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */
    /*    Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG,  0xcb4[29:28] = 2b'10 => Ant to WLG */
    if (rfe_type->ext_ant_switch_ctrl_polarity)
        switch_polatiry_inverse =  !switch_polatiry_inverse;
 
    /* swap control polarity if 1-Ant at Aux */
    if (rfe_type->ant_at_main_port == false)
        switch_polatiry_inverse =  !switch_polatiry_inverse;
 
    if (is_5g)
        pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA;
    else
        pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG;
 
    switch (pos_type) {
    default:
    case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA:
 
        break;
    case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG:
        if (!rfe_type->wlg_Locate_at_btg)
            switch_polatiry_inverse =  !switch_polatiry_inverse;
        break;
    }
 
    if (pwifionlycfg->haldata_info.ant_div_cfg)
        ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;
    else
        ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW;
 
 
    switch (ctrl_type) {
    default:
    case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW:
        halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c,  0x01800000, 0x2);
 
        /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
        halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff,    0x77);
 
        regval_0xcb7 = (switch_polatiry_inverse == false ? 0x1 : 0x2);
 
        /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
        halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x30000000,    regval_0xcb7);
        break;
 
    case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
        halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c,  0x01800000, 0x2);
 
        /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
        halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff,    0x88);
 
        /* no regval_0xcb7 setup required, because    antenna switch control value by antenna diversity */
 
        break;
 
    }
 
}
 
 
VOID halbtc8821c_wifi_only_set_rfe_type(
    IN struct wifi_only_cfg *pwifionlycfg
    )
{
 
    /* the following setup should be got from Efuse in the future */
    rfe_type->rfe_module_type = (pwifionlycfg->haldata_info.rfe_type) & 0x1f;
 
    rfe_type->ext_ant_switch_ctrl_polarity = 0;
 
    switch (rfe_type->rfe_module_type) {
    case 0:
    default:
        rfe_type->ext_ant_switch_exist = true;
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;          /*2-Ant, DPDT, WLG*/
        rfe_type->wlg_Locate_at_btg = false;
        rfe_type->ant_at_main_port = true;
        break;
    case 1:
        rfe_type->ext_ant_switch_exist = true;
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT;          /*1-Ant, Main, DPDT or SPDT, WLG */
        rfe_type->wlg_Locate_at_btg = false;
        rfe_type->ant_at_main_port = true;
        break;
    case 2:
        rfe_type->ext_ant_switch_exist = true;
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT;            /*1-Ant, Main, DPDT or SPDT, BTG */
        rfe_type->wlg_Locate_at_btg = true;
        rfe_type->ant_at_main_port = true;
        break;
    case 3:
        rfe_type->ext_ant_switch_exist = true;
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;          /*1-Ant, Aux, DPDT, WLG */
        rfe_type->wlg_Locate_at_btg = false;
        rfe_type->ant_at_main_port = false;
        break;
    case 4:
        rfe_type->ext_ant_switch_exist = true;
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;          /*1-Ant, Aux, DPDT, BTG */
        rfe_type->wlg_Locate_at_btg = true;
        rfe_type->ant_at_main_port = false;
        break;
    case 5:
        rfe_type->ext_ant_switch_exist = false;                     /*2-Ant, no antenna switch, WLG*/
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
        rfe_type->wlg_Locate_at_btg = false;
        rfe_type->ant_at_main_port = true;
        break;
    case 6:
        rfe_type->ext_ant_switch_exist = false;                 /*2-Ant, no antenna switch, WLG*/
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
        rfe_type->wlg_Locate_at_btg = false;
        rfe_type->ant_at_main_port = true;
        break;
    case 7:
        rfe_type->ext_ant_switch_exist = true;                /*2-Ant, DPDT, BTG*/
        rfe_type->ext_ant_switch_type =
            BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;
        rfe_type->wlg_Locate_at_btg = true;
        rfe_type->ant_at_main_port = true;
        break;
    }
 
}
 
 
VOID
ex_hal8821c_wifi_only_hw_config(
    IN struct wifi_only_cfg *pwifionlycfg
    )
{
    halbtc8821c_wifi_only_set_rfe_type(pwifionlycfg);
 
    /* set gnt_wl, gnt_bt control owner to WL*/
    halwifionly_phy_set_bb_reg(pwifionlycfg, 0x70, 0x400000, 0x1);
 
    /*gnt_wl=1 , gnt_bt=0*/
    halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1704, 0xffffffff, 0x7700);
    halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1700, 0xffffffff, 0xc00f0038);
}
 
VOID
ex_hal8821c_wifi_only_scannotify(
    IN struct wifi_only_cfg *pwifionlycfg,
    IN u1Byte  is_5g
    )
{
    hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
}
 
VOID
ex_hal8821c_wifi_only_switchbandnotify(
    IN struct wifi_only_cfg *pwifionlycfg,
    IN u1Byte  is_5g
    )
{
    hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
}