blob: 57382631c1adbf505fff80d3c40179a1e6e518c8 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26
27#include "wl1271_init.h"
28#include "wl12xx_80211.h"
29#include "wl1271_acx.h"
30#include "wl1271_cmd.h"
31#include "wl1271_reg.h"
32
33static int wl1271_init_hwenc_config(struct wl1271 *wl)
34{
35 int ret;
36
37 ret = wl1271_acx_feature_cfg(wl);
38 if (ret < 0) {
39 wl1271_warning("couldn't set feature config");
40 return ret;
41 }
42
43 ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
44 if (ret < 0) {
45 wl1271_warning("couldn't set default key");
46 return ret;
47 }
48
49 return 0;
50}
51
52static int wl1271_init_templates_config(struct wl1271 *wl)
53{
54 int ret;
55
56 /* send empty templates for fw memory reservation */
57 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
58 sizeof(struct wl12xx_probe_req_template));
59 if (ret < 0)
60 return ret;
61
62 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0)
65 return ret;
66
67 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
68 sizeof(struct wl12xx_ps_poll_template));
69 if (ret < 0)
70 return ret;
71
72 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
73 sizeof
74 (struct wl12xx_qos_null_data_template));
75 if (ret < 0)
76 return ret;
77
78 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
79 sizeof
80 (struct wl12xx_probe_resp_template));
81 if (ret < 0)
82 return ret;
83
84 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
85 sizeof
86 (struct wl12xx_beacon_template));
87 if (ret < 0)
88 return ret;
89
90 return 0;
91}
92
93static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
94{
95 int ret;
96
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +030097 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030098 if (ret < 0)
99 return ret;
100
101 ret = wl1271_acx_rx_config(wl, config, filter);
102 if (ret < 0)
103 return ret;
104
105 return 0;
106}
107
108static int wl1271_init_phy_config(struct wl1271 *wl)
109{
110 int ret;
111
112 ret = wl1271_acx_pd_threshold(wl);
113 if (ret < 0)
114 return ret;
115
116 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
117 if (ret < 0)
118 return ret;
119
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300120 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300121 if (ret < 0)
122 return ret;
123
124 ret = wl1271_acx_service_period_timeout(wl);
125 if (ret < 0)
126 return ret;
127
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300128 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300129 if (ret < 0)
130 return ret;
131
132 return 0;
133}
134
135static int wl1271_init_beacon_filter(struct wl1271 *wl)
136{
137 int ret;
138
Juuso Oikarinen19221672009-10-08 21:56:35 +0300139 /* disable beacon filtering at this stage */
140 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300141 if (ret < 0)
142 return ret;
143
144 ret = wl1271_acx_beacon_filter_table(wl);
145 if (ret < 0)
146 return ret;
147
148 return 0;
149}
150
151static int wl1271_init_pta(struct wl1271 *wl)
152{
153 int ret;
154
155 ret = wl1271_acx_sg_enable(wl);
156 if (ret < 0)
157 return ret;
158
159 ret = wl1271_acx_sg_cfg(wl);
160 if (ret < 0)
161 return ret;
162
163 return 0;
164}
165
166static int wl1271_init_energy_detection(struct wl1271 *wl)
167{
168 int ret;
169
170 ret = wl1271_acx_cca_threshold(wl);
171 if (ret < 0)
172 return ret;
173
174 return 0;
175}
176
177static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
178{
179 int ret;
180
181 ret = wl1271_acx_bcn_dtim_options(wl);
182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
188static int wl1271_init_general_parms(struct wl1271 *wl)
189{
190 struct wl1271_general_parms *gen_parms;
191 int ret;
192
193 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
194 if (!gen_parms)
195 return -ENOMEM;
196
197 gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
198
Juuso Oikarinen2cc8d4d2009-10-13 12:47:38 +0300199 /*
200 * FIXME: The firmware crashes on boot with REF_CLK_38_4_E as clock.
201 * according to TI engineers, ref clk 5 is an unofficial
202 * 38.4 XTAL clock config, which seems to boot the device.
203 * Restore correct value once the real problem source is
204 * identified.
205 */
206 gen_parms->ref_clk = 5; /* REF_CLK_38_4_E; */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300207 /* FIXME: magic numbers */
208 gen_parms->settling_time = 5;
209 gen_parms->clk_valid_on_wakeup = 0;
210 gen_parms->dc2dcmode = 0;
211 gen_parms->single_dual_band = 0;
Juuso Oikarinen8bcfcb12009-10-12 15:08:55 +0300212 gen_parms->tx_bip_fem_autodetect = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300213 gen_parms->tx_bip_fem_manufacturer = 1;
214 gen_parms->settings = 1;
215
216 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
217 if (ret < 0) {
218 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
219 return ret;
220 }
221
222 kfree(gen_parms);
223 return 0;
224}
225
226static int wl1271_init_radio_parms(struct wl1271 *wl)
227{
228 /*
229 * FIXME: All these magic numbers should be moved to some place where
230 * they can be configured (separate file?)
231 */
232
233 struct wl1271_radio_parms *radio_parms;
234 int ret;
235 u8 compensation[] = { 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8, 0xfc, 0x00,
236 0x08, 0x10, 0xf0, 0xf8, 0x00, 0x0a, 0x14 };
237
238 u8 tx_rate_limits_normal[] = { 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 };
239 u8 tx_rate_limits_degraded[] = { 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 };
240
241 u8 tx_channel_limits_11b[] = { 0x22, 0x50, 0x50, 0x50,
242 0x50, 0x50, 0x50, 0x50,
243 0x50, 0x50, 0x22, 0x50,
244 0x22, 0x50 };
245
246 u8 tx_channel_limits_ofdm[] = { 0x20, 0x50, 0x50, 0x50,
247 0x50, 0x50, 0x50, 0x50,
248 0x50, 0x50, 0x20, 0x50,
249 0x20, 0x50 };
250
251 u8 tx_pdv_rate_offsets[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
252
253 u8 tx_ibias[] = { 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 };
254
255 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
256 if (!radio_parms)
257 return -ENOMEM;
258
259 radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
260
261 /* Static radio parameters */
262 radio_parms->rx_trace_loss = 10;
263 radio_parms->tx_trace_loss = 10;
264 memcpy(radio_parms->rx_rssi_and_proc_compens, compensation,
265 sizeof(compensation));
266
267 /* We don't set the 5GHz -- N/A */
268
269 /* Dynamic radio parameters */
270 radio_parms->tx_ref_pd_voltage = cpu_to_le16(0x24e);
271 radio_parms->tx_ref_power = 0x78;
272 radio_parms->tx_offset_db = 0x0;
273
274 memcpy(radio_parms->tx_rate_limits_normal, tx_rate_limits_normal,
275 sizeof(tx_rate_limits_normal));
276 memcpy(radio_parms->tx_rate_limits_degraded, tx_rate_limits_degraded,
277 sizeof(tx_rate_limits_degraded));
278
279 memcpy(radio_parms->tx_channel_limits_11b, tx_channel_limits_11b,
280 sizeof(tx_channel_limits_11b));
281 memcpy(radio_parms->tx_channel_limits_ofdm, tx_channel_limits_ofdm,
282 sizeof(tx_channel_limits_ofdm));
283 memcpy(radio_parms->tx_pdv_rate_offsets, tx_pdv_rate_offsets,
284 sizeof(tx_pdv_rate_offsets));
285 memcpy(radio_parms->tx_ibias, tx_ibias,
286 sizeof(tx_ibias));
287
288 radio_parms->rx_fem_insertion_loss = 0x14;
289
290 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
291 if (ret < 0)
292 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
293
294 kfree(radio_parms);
295 return ret;
296}
297
298int wl1271_hw_init(struct wl1271 *wl)
299{
300 int ret;
301
302 ret = wl1271_init_general_parms(wl);
303 if (ret < 0)
304 return ret;
305
306 ret = wl1271_init_radio_parms(wl);
307 if (ret < 0)
308 return ret;
309
310 /* Template settings */
311 ret = wl1271_init_templates_config(wl);
312 if (ret < 0)
313 return ret;
314
315 /* Default memory configuration */
316 ret = wl1271_acx_init_mem_config(wl);
317 if (ret < 0)
318 return ret;
319
320 /* RX config */
321 ret = wl1271_init_rx_config(wl,
322 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
323 RX_FILTER_OPTION_DEF);
324 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
325 RX_FILTER_OPTION_FILTER_ALL); */
326 if (ret < 0)
327 goto out_free_memmap;
328
329 /* PHY layer config */
330 ret = wl1271_init_phy_config(wl);
331 if (ret < 0)
332 goto out_free_memmap;
333
Juuso Oikarinen34415232009-10-08 21:56:33 +0300334 /* Initialize connection monitoring thresholds */
335 ret = wl1271_acx_conn_monit_params(wl);
336 if (ret < 0)
337 goto out_free_memmap;
338
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300339 /* Beacon filtering */
340 ret = wl1271_init_beacon_filter(wl);
341 if (ret < 0)
342 goto out_free_memmap;
343
344 /* Configure TX patch complete interrupt behavior */
345 ret = wl1271_acx_tx_config_options(wl);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* RX complete interrupt pacing */
350 ret = wl1271_acx_init_rx_interrupt(wl);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 /* Bluetooth WLAN coexistence */
355 ret = wl1271_init_pta(wl);
356 if (ret < 0)
357 goto out_free_memmap;
358
359 /* Energy detection */
360 ret = wl1271_init_energy_detection(wl);
361 if (ret < 0)
362 goto out_free_memmap;
363
364 /* Beacons and boradcast settings */
365 ret = wl1271_init_beacon_broadcast(wl);
366 if (ret < 0)
367 goto out_free_memmap;
368
369 /* Default fragmentation threshold */
370 ret = wl1271_acx_frag_threshold(wl);
371 if (ret < 0)
372 goto out_free_memmap;
373
374 /* Default TID configuration */
375 ret = wl1271_acx_tid_cfg(wl);
376 if (ret < 0)
377 goto out_free_memmap;
378
379 /* Default AC configuration */
380 ret = wl1271_acx_ac_cfg(wl);
381 if (ret < 0)
382 goto out_free_memmap;
383
384 /* Configure TX rate classes */
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +0300385 ret = wl1271_acx_rate_policies(wl, ACX_RATE_MASK_ALL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386 if (ret < 0)
387 goto out_free_memmap;
388
389 /* Enable data path */
390 ret = wl1271_cmd_data_path(wl, wl->channel, 1);
391 if (ret < 0)
392 goto out_free_memmap;
393
394 /* Configure for ELP power saving */
395 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
396 if (ret < 0)
397 goto out_free_memmap;
398
399 /* Configure HW encryption */
400 ret = wl1271_init_hwenc_config(wl);
401 if (ret < 0)
402 goto out_free_memmap;
403
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +0300404 /* Configure smart reflex */
405 ret = wl1271_acx_smart_reflex(wl);
406 if (ret < 0)
407 goto out_free_memmap;
408
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300409 return 0;
410
411 out_free_memmap:
412 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300413 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300414
415 return ret;
416}