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