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#define _HCI_HAL_INIT_C_
30
31#include "osdep_service.h"
32#include "drv_types.h"
33#include "usb_ops.h"
34#include "usb_osintf.h"
35
36u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
37{
38 u8 val8 = 0;
39 u8 ret = _SUCCESS;
40 int PollingCnt = 20;
41 struct registry_priv *pregistrypriv = &padapter->registrypriv;
42
43 if (pregistrypriv->chip_version == RTL8712_FPGA) {
44 val8 = 0x01;
45
46 r8712_write8(padapter, SYS_CLKR, val8);
47 val8 = r8712_read8(padapter, SPS1_CTRL);
48 val8 = val8 | 0x01;
49
50 r8712_write8(padapter, SPS1_CTRL, val8);
51 val8 = r8712_read8(padapter, AFE_MISC);
52 val8 = val8 | 0x01;
53
54 r8712_write8(padapter, AFE_MISC, val8);
55 val8 = r8712_read8(padapter, LDOA15_CTRL);
56 val8 = val8 | 0x01;
57
58 r8712_write8(padapter, LDOA15_CTRL, val8);
59 val8 = r8712_read8(padapter, SPS1_CTRL);
60 val8 = val8 | 0x02;
61
62 r8712_write8(padapter, SPS1_CTRL, val8);
63 val8 = r8712_read8(padapter, AFE_MISC);
64 val8 = val8 | 0x02;
65
66 r8712_write8(padapter, AFE_MISC, val8);
67 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
68 val8 = val8 | 0x08;
69
70 r8712_write8(padapter, SYS_ISO_CTRL + 1, val8);
71 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
72 val8 = val8 & 0xEF;
73
74 r8712_write8(padapter, SYS_ISO_CTRL + 1, val8);
75 val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
76 val8 = val8 & 0xFB;
77
78 r8712_write8(padapter, AFE_XTAL_CTRL + 1, val8);
79 val8 = r8712_read8(padapter, AFE_PLL_CTRL);
80 val8 = val8 | 0x01;
81
82 r8712_write8(padapter, AFE_PLL_CTRL, val8);
83 val8 = 0xEE;
84
85 r8712_write8(padapter, SYS_ISO_CTRL, val8);
86 val8 = r8712_read8(padapter, SYS_CLKR + 1);
87 val8 = val8 | 0x08;
88
89 r8712_write8(padapter, SYS_CLKR + 1, val8);
90 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
91 val8 = val8 | 0x08;
92
93 r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
94 val8 = val8 | 0x80;
95
96 r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
97 val8 = r8712_read8(padapter, SYS_CLKR + 1);
98 val8 = (val8 | 0x80) & 0xBF;
99
100 r8712_write8(padapter, SYS_CLKR + 1, val8);
101 val8 = 0xFC;
102 r8712_write8(padapter, CR, val8);
103 val8 = 0x37;
104 r8712_write8(padapter, CR + 1, val8);
105
106 r8712_write8(padapter, 0x102500ab, r8712_read8(padapter,
107 0x102500ab) | BIT(6) | BIT(7));
108
109 r8712_write8(padapter, 0x10250008, r8712_read8(padapter,
110 0x10250008) & 0xfffffffb);
111 } else if (pregistrypriv->chip_version == RTL8712_1stCUT) {
112
113 r8712_write8(padapter, SPS0_CTRL + 1, 0x53);
114 r8712_write8(padapter, SPS0_CTRL, 0x57);
115
116
117
118 val8 = r8712_read8(padapter, AFE_MISC);
119 r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
120 AFE_MISC_MBEN));
121
122 val8 = r8712_read8(padapter, LDOA15_CTRL);
123 r8712_write8(padapter, LDOA15_CTRL, (val8 | LDA15_EN));
124 val8 = r8712_read8(padapter, SPS1_CTRL);
125 r8712_write8(padapter, SPS1_CTRL, (val8 | SPS1_LDEN));
126 msleep(20);
127
128 val8 = r8712_read8(padapter, SPS1_CTRL);
129 r8712_write8(padapter, SPS1_CTRL, (val8 | SPS1_SWEN));
130 r8712_write32(padapter, SPS1_CTRL, 0x00a7b267);
131 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
132 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
133
134 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
135 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x20));
136 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
137 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 & 0x6F));
138
139 val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
140 r8712_write8(padapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
141
142 val8 = r8712_read8(padapter, AFE_PLL_CTRL);
143 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
144
145 val8 = r8712_read8(padapter, SYS_ISO_CTRL);
146 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
147
148 val8 = r8712_read8(padapter, SYS_CLKR);
149 r8712_write8(padapter, SYS_CLKR, val8 & (~SYS_CLKSEL));
150
151 val8 = r8712_read8(padapter, SYS_CLKR);
152
153 val8 = r8712_read8(padapter, SYS_CLKR + 1);
154 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x18));
155
156 r8712_write8(padapter, PMC_FSM, 0x02);
157
158 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
159 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x08));
160
161 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
162 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x80));
163
164 val8 = r8712_read8(padapter, SYS_CLKR + 1);
165 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
166 r8712_write8(padapter, CR, 0xFC);
167 r8712_write8(padapter, CR + 1, 0x37);
168
169 val8 = r8712_read8(padapter, 0x1025FE5c);
170 r8712_write8(padapter, 0x1025FE5c, (val8|BIT(7)));
171 val8 = r8712_read8(padapter, 0x102500ab);
172 r8712_write8(padapter, 0x102500ab, (val8|BIT(6)|BIT(7)));
173
174 val8 = r8712_read8(padapter, SYS_CLKR);
175 r8712_write8(padapter, SYS_CLKR, val8&(~CPU_CLKSEL));
176 } else if (pregistrypriv->chip_version == RTL8712_2ndCUT ||
177 pregistrypriv->chip_version == RTL8712_3rdCUT) {
178
179
180
181 r8712_write8(padapter, 0x37, 0xb0);
182 msleep(20);
183 r8712_write8(padapter, 0x37, 0x30);
184
185
186
187
188 val8 = r8712_read8(padapter, SYS_CLKR + 1);
189 if (val8 & 0x80) {
190 val8 &= 0x3f;
191 r8712_write8(padapter, SYS_CLKR + 1, val8);
192 }
193 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
194 val8 &= 0x73;
195 r8712_write8(padapter, SYS_FUNC_EN + 1, val8);
196 msleep(20);
197
198
199
200 r8712_write8(padapter, SPS0_CTRL + 1, 0x53);
201 r8712_write8(padapter, SPS0_CTRL, 0x57);
202 val8 = r8712_read8(padapter, AFE_MISC);
203
204 r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN));
205 r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
206 AFE_MISC_MBEN | AFE_MISC_I32_EN));
207
208 val8 = r8712_read8(padapter, LDOA15_CTRL);
209 r8712_write8(padapter, LDOA15_CTRL, (val8 | LDA15_EN));
210
211 val8 = r8712_read8(padapter, LDOV12D_CTRL);
212 r8712_write8(padapter, LDOV12D_CTRL, (val8 | LDV12_EN));
213 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
214 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
215
216 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
217 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x20));
218
219 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
220 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 & 0x68));
221
222 val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
223 r8712_write8(padapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
224
225 val8 = r8712_read8(padapter, AFE_PLL_CTRL);
226 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
227
228
229
230
231
232 udelay(500);
233 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x51));
234 udelay(500);
235 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
236 udelay(500);
237
238 val8 = r8712_read8(padapter, SYS_ISO_CTRL);
239 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
240
241 r8712_write8(padapter, SYS_CLKR, 0x00);
242
243
244
245 val8 = r8712_read8(padapter, SYS_CLKR);
246 r8712_write8(padapter, SYS_CLKR, (val8 | 0xa0));
247
248 val8 = r8712_read8(padapter, SYS_CLKR + 1);
249 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x18));
250
251 r8712_write8(padapter, PMC_FSM, 0x02);
252
253 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
254 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x08));
255
256 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
257 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x80));
258
259 val8 = r8712_read8(padapter, SYS_CLKR + 1);
260 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
261 r8712_write8(padapter, CR, 0xFC);
262 r8712_write8(padapter, CR + 1, 0x37);
263
264 val8 = r8712_read8(padapter, 0x1025FE5c);
265 r8712_write8(padapter, 0x1025FE5c, (val8 | BIT(7)));
266
267 val8 = r8712_read8(padapter, SYS_CLKR);
268 r8712_write8(padapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
269
270 r8712_write8(padapter, 0x1025fe1c, 0x80);
271
272
273
274 do {
275 val8 = r8712_read8(padapter, TCR);
276 if ((val8 & _TXDMA_INIT_VALUE) == _TXDMA_INIT_VALUE)
277 break;
278 udelay(5);
279 } while (PollingCnt--);
280
281 if (PollingCnt <= 0) {
282 val8 = r8712_read8(padapter, CR);
283 r8712_write8(padapter, CR, val8&(~_TXDMA_EN));
284 udelay(2);
285
286 r8712_write8(padapter, CR, val8|_TXDMA_EN);
287 }
288 } else
289 ret = _FAIL;
290 return ret;
291}
292
293unsigned int r8712_usb_inirp_init(struct _adapter *padapter)
294{
295 u8 i;
296 struct recv_buf *precvbuf;
297 struct intf_hdl *pintfhdl = &padapter->pio_queue->intf;
298 struct recv_priv *precvpriv = &(padapter->recvpriv);
299
300 precvpriv->ff_hwaddr = RTL8712_DMA_RX0FF;
301
302 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
303 for (i = 0; i < NR_RECVBUFF; i++) {
304 if (r8712_usb_read_port(pintfhdl, precvpriv->ff_hwaddr, 0,
305 (unsigned char *)precvbuf) == false)
306 return _FAIL;
307 precvbuf++;
308 precvpriv->free_recv_buf_queue_cnt--;
309 }
310 return _SUCCESS;
311}
312
313unsigned int r8712_usb_inirp_deinit(struct _adapter *padapter)
314{
315 r8712_usb_read_port_cancel(padapter);
316 return _SUCCESS;
317}
318