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
201 r8712_write8(padapter, SPS0_CTRL + 1, 0x53);
202 r8712_write8(padapter, SPS0_CTRL, 0x57);
203 val8 = r8712_read8(padapter, AFE_MISC);
204
205 r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN));
206 r8712_write8(padapter, AFE_MISC, (val8 | AFE_MISC_BGEN |
207 AFE_MISC_MBEN | AFE_MISC_I32_EN));
208
209 val8 = r8712_read8(padapter, LDOA15_CTRL);
210 r8712_write8(padapter, LDOA15_CTRL, (val8 | LDA15_EN));
211
212 val8 = r8712_read8(padapter, LDOV12D_CTRL);
213 r8712_write8(padapter, LDOV12D_CTRL, (val8 | LDV12_EN));
214 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
215 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 | 0x08));
216
217 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
218 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x20));
219
220 val8 = r8712_read8(padapter, SYS_ISO_CTRL + 1);
221 r8712_write8(padapter, SYS_ISO_CTRL + 1, (val8 & 0x68));
222
223 val8 = r8712_read8(padapter, AFE_XTAL_CTRL + 1);
224 r8712_write8(padapter, AFE_XTAL_CTRL + 1, (val8 & 0xfb));
225
226 val8 = r8712_read8(padapter, AFE_PLL_CTRL);
227 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
228
229
230
231
232
233 udelay(500);
234 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x51));
235 udelay(500);
236 r8712_write8(padapter, AFE_PLL_CTRL, (val8 | 0x11));
237 udelay(500);
238
239 val8 = r8712_read8(padapter, SYS_ISO_CTRL);
240 r8712_write8(padapter, SYS_ISO_CTRL, (val8 & 0xEE));
241
242 r8712_write8(padapter, SYS_CLKR, 0x00);
243
244
245
246 val8 = r8712_read8(padapter, SYS_CLKR);
247 r8712_write8(padapter, SYS_CLKR, (val8 | 0xa0));
248
249 val8 = r8712_read8(padapter, SYS_CLKR + 1);
250 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x18));
251
252 r8712_write8(padapter, PMC_FSM, 0x02);
253
254 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
255 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x08));
256
257 val8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
258 r8712_write8(padapter, SYS_FUNC_EN + 1, (val8 | 0x80));
259
260 val8 = r8712_read8(padapter, SYS_CLKR + 1);
261 r8712_write8(padapter, SYS_CLKR + 1, (val8 | 0x80) & 0xBF);
262 r8712_write8(padapter, CR, 0xFC);
263 r8712_write8(padapter, CR + 1, 0x37);
264
265 val8 = r8712_read8(padapter, 0x1025FE5c);
266 r8712_write8(padapter, 0x1025FE5c, (val8 | BIT(7)));
267
268 val8 = r8712_read8(padapter, SYS_CLKR);
269 r8712_write8(padapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
270
271 r8712_write8(padapter, 0x1025fe1c, 0x80);
272
273
274
275 do {
276 val8 = r8712_read8(padapter, TCR);
277 if ((val8 & _TXDMA_INIT_VALUE) == _TXDMA_INIT_VALUE)
278 break;
279 udelay(5);
280 } while (PollingCnt--);
281
282 if (PollingCnt <= 0) {
283 val8 = r8712_read8(padapter, CR);
284 r8712_write8(padapter, CR, val8 & (~_TXDMA_EN));
285 udelay(2);
286
287 r8712_write8(padapter, CR, val8 | _TXDMA_EN);
288 }
289 } else {
290 ret = _FAIL;
291 }
292 return ret;
293}
294
295unsigned int r8712_usb_inirp_init(struct _adapter *padapter)
296{
297 u8 i;
298 struct recv_buf *precvbuf;
299 struct intf_hdl *pintfhdl = &padapter->pio_queue->intf;
300 struct recv_priv *precvpriv = &(padapter->recvpriv);
301
302 precvpriv->ff_hwaddr = RTL8712_DMA_RX0FF;
303
304 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
305 for (i = 0; i < NR_RECVBUFF; i++) {
306 if (r8712_usb_read_port(pintfhdl, precvpriv->ff_hwaddr, 0,
307 (unsigned char *)precvbuf) == false)
308 return _FAIL;
309 precvbuf++;
310 precvpriv->free_recv_buf_queue_cnt--;
311 }
312 return _SUCCESS;
313}
314
315unsigned int r8712_usb_inirp_deinit(struct _adapter *padapter)
316{
317 r8712_usb_read_port_cancel(padapter);
318 return _SUCCESS;
319}
320