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