blob: 38f3e8ba2628c8d54f32c7dcfdc18ed8f0e38eca [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
Luciano Coelho2f826f52010-03-26 12:53:21 +02004 * Copyright (C) 2008-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005 *
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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030025
Shahar Levi00d20102010-11-08 11:20:10 +000026#include "acx.h"
27#include "reg.h"
28#include "boot.h"
29#include "io.h"
30#include "event.h"
Arik Nemtsovae113b52010-10-16 18:45:07 +020031#include "rx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030032
33static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
34 [PART_DOWN] = {
35 .mem = {
36 .start = 0x00000000,
37 .size = 0x000177c0
38 },
39 .reg = {
40 .start = REGISTERS_BASE,
41 .size = 0x00008800
42 },
Juuso Oikarinen451de972009-10-12 15:08:46 +030043 .mem2 = {
44 .start = 0x00000000,
45 .size = 0x00000000
46 },
47 .mem3 = {
48 .start = 0x00000000,
49 .size = 0x00000000
50 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030051 },
52
53 [PART_WORK] = {
54 .mem = {
55 .start = 0x00040000,
56 .size = 0x00014fc0
57 },
58 .reg = {
59 .start = REGISTERS_BASE,
Juuso Oikarinen451de972009-10-12 15:08:46 +030060 .size = 0x0000a000
61 },
62 .mem2 = {
63 .start = 0x003004f8,
64 .size = 0x00000004
65 },
66 .mem3 = {
67 .start = 0x00040404,
68 .size = 0x00000000
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030069 },
70 },
71
72 [PART_DRPW] = {
73 .mem = {
74 .start = 0x00040000,
75 .size = 0x00014fc0
76 },
77 .reg = {
78 .start = DRPW_BASE,
79 .size = 0x00006000
Juuso Oikarinen451de972009-10-12 15:08:46 +030080 },
81 .mem2 = {
82 .start = 0x00000000,
83 .size = 0x00000000
84 },
85 .mem3 = {
86 .start = 0x00000000,
87 .size = 0x00000000
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030088 }
89 }
90};
91
92static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
93{
94 u32 cpu_ctrl;
95
96 /* 10.5.0 run the firmware (I) */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020097 cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030098
99 /* 10.5.1 run the firmware (II) */
100 cpu_ctrl |= flag;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200101 wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300102}
103
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100104static void wl1271_parse_fw_ver(struct wl1271 *wl)
105{
106 int ret;
107
108 ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
109 &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
110 &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
111 &wl->chip.fw_ver[4]);
112
113 if (ret != 5) {
114 wl1271_warning("fw version incorrect value");
115 memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
116 return;
117 }
118}
119
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300120static void wl1271_boot_fw_version(struct wl1271 *wl)
121{
122 struct wl1271_static_data static_data;
123
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200124 wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
125 false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300126
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100127 strncpy(wl->chip.fw_ver_str, static_data.fw_version,
128 sizeof(wl->chip.fw_ver_str));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300129
130 /* make sure the string is NULL-terminated */
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100131 wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
132
133 wl1271_parse_fw_ver(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300134}
135
136static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
137 size_t fw_data_len, u32 dest)
138{
Juuso Oikarinen451de972009-10-12 15:08:46 +0300139 struct wl1271_partition_set partition;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300140 int addr, chunk_num, partition_limit;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300141 u8 *p, *chunk;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300142
143 /* whal_FwCtrl_LoadFwImageSm() */
144
145 wl1271_debug(DEBUG_BOOT, "starting firmware upload");
146
Luciano Coelho73d0a132009-08-11 11:58:27 +0300147 wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
148 fw_data_len, CHUNK_SIZE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300149
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300150 if ((fw_data_len % 4) != 0) {
151 wl1271_error("firmware length not multiple of four");
152 return -EIO;
153 }
154
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300155 chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
Juuso Oikarinened3177882009-10-13 12:47:57 +0300156 if (!chunk) {
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300157 wl1271_error("allocation for firmware upload chunk failed");
158 return -ENOMEM;
159 }
160
Juuso Oikarinen451de972009-10-12 15:08:46 +0300161 memcpy(&partition, &part_table[PART_DOWN], sizeof(partition));
162 partition.mem.start = dest;
163 wl1271_set_partition(wl, &partition);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300164
165 /* 10.1 set partition limit and chunk num */
166 chunk_num = 0;
167 partition_limit = part_table[PART_DOWN].mem.size;
168
169 while (chunk_num < fw_data_len / CHUNK_SIZE) {
170 /* 10.2 update partition, if needed */
171 addr = dest + (chunk_num + 2) * CHUNK_SIZE;
172 if (addr > partition_limit) {
173 addr = dest + chunk_num * CHUNK_SIZE;
174 partition_limit = chunk_num * CHUNK_SIZE +
175 part_table[PART_DOWN].mem.size;
Juuso Oikarinen451de972009-10-12 15:08:46 +0300176 partition.mem.start = addr;
177 wl1271_set_partition(wl, &partition);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300178 }
179
180 /* 10.3 upload the chunk */
181 addr = dest + chunk_num * CHUNK_SIZE;
182 p = buf + chunk_num * CHUNK_SIZE;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300183 memcpy(chunk, p, CHUNK_SIZE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300184 wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
185 p, addr);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200186 wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300187
188 chunk_num++;
189 }
190
191 /* 10.4 upload the last chunk */
192 addr = dest + chunk_num * CHUNK_SIZE;
193 p = buf + chunk_num * CHUNK_SIZE;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300194 memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
Luciano Coelho73d0a132009-08-11 11:58:27 +0300195 wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300196 fw_data_len % CHUNK_SIZE, p, addr);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200197 wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300198
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300199 kfree(chunk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300200 return 0;
201}
202
203static int wl1271_boot_upload_firmware(struct wl1271 *wl)
204{
205 u32 chunks, addr, len;
Juuso Oikarinened3177882009-10-13 12:47:57 +0300206 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300207 u8 *fw;
208
209 fw = wl->fw;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300210 chunks = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300211 fw += sizeof(u32);
212
213 wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
214
215 while (chunks--) {
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300216 addr = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300217 fw += sizeof(u32);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300218 len = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300219 fw += sizeof(u32);
220
221 if (len > 300000) {
222 wl1271_info("firmware chunk too long: %u", len);
223 return -EINVAL;
224 }
225 wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
226 chunks, addr, len);
Juuso Oikarinened3177882009-10-13 12:47:57 +0300227 ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
228 if (ret != 0)
229 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300230 fw += len;
231 }
232
Juuso Oikarinened3177882009-10-13 12:47:57 +0300233 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300234}
235
236static int wl1271_boot_upload_nvs(struct wl1271 *wl)
237{
238 size_t nvs_len, burst_len;
239 int i;
240 u32 dest_addr, val;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200241 u8 *nvs_ptr, *nvs_aligned;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300242
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200243 if (wl->nvs == NULL)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300244 return -ENODEV;
245
Shahar Levibc765bf2011-03-06 16:32:10 +0200246 if (wl->chip.id == CHIP_ID_1283_PG20) {
247 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
Juuso Oikarinen02fabb02010-08-19 04:41:15 +0200248
Shahar Levibc765bf2011-03-06 16:32:10 +0200249 if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
250 if (nvs->general_params.dual_mode_select)
251 wl->enable_11a = true;
252 } else {
253 wl1271_error("nvs size is not as expected: %zu != %zu",
254 wl->nvs_len,
255 sizeof(struct wl128x_nvs_file));
256 kfree(wl->nvs);
257 wl->nvs = NULL;
258 wl->nvs_len = 0;
259 return -EILSEQ;
260 }
Juuso Oikarinen02fabb02010-08-19 04:41:15 +0200261
Shahar Levibc765bf2011-03-06 16:32:10 +0200262 /* only the first part of the NVS needs to be uploaded */
263 nvs_len = sizeof(nvs->nvs);
264 nvs_ptr = (u8 *)nvs->nvs;
265
266 } else {
267 struct wl1271_nvs_file *nvs =
268 (struct wl1271_nvs_file *)wl->nvs;
269 /*
270 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
271 * band configurations) can be removed when those NVS files stop
272 * floating around.
273 */
274 if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
275 wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
276 /* for now 11a is unsupported in AP mode */
277 if (wl->bss_type != BSS_TYPE_AP_BSS &&
278 nvs->general_params.dual_mode_select)
279 wl->enable_11a = true;
280 }
281
282 if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
283 (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
284 wl->enable_11a)) {
285 wl1271_error("nvs size is not as expected: %zu != %zu",
286 wl->nvs_len, sizeof(struct wl1271_nvs_file));
287 kfree(wl->nvs);
288 wl->nvs = NULL;
289 wl->nvs_len = 0;
290 return -EILSEQ;
291 }
292
293 /* only the first part of the NVS needs to be uploaded */
294 nvs_len = sizeof(nvs->nvs);
295 nvs_ptr = (u8 *) nvs->nvs;
296 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300297
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +0200298 /* update current MAC address to NVS */
299 nvs_ptr[11] = wl->mac_addr[0];
300 nvs_ptr[10] = wl->mac_addr[1];
301 nvs_ptr[6] = wl->mac_addr[2];
302 nvs_ptr[5] = wl->mac_addr[3];
303 nvs_ptr[4] = wl->mac_addr[4];
304 nvs_ptr[3] = wl->mac_addr[5];
305
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306 /*
307 * Layout before the actual NVS tables:
308 * 1 byte : burst length.
309 * 2 bytes: destination address.
310 * n bytes: data to burst copy.
311 *
312 * This is ended by a 0 length, then the NVS tables.
313 */
314
315 /* FIXME: Do we need to check here whether the LSB is 1? */
316 while (nvs_ptr[0]) {
317 burst_len = nvs_ptr[0];
318 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
319
Juuso Oikarinen2f63b012010-08-10 06:38:35 +0200320 /*
321 * Due to our new wl1271_translate_reg_addr function,
322 * we need to add the REGISTER_BASE to the destination
323 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324 dest_addr += REGISTERS_BASE;
325
326 /* We move our pointer to the data */
327 nvs_ptr += 3;
328
329 for (i = 0; i < burst_len; i++) {
330 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
331 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
332
333 wl1271_debug(DEBUG_BOOT,
334 "nvs burst write 0x%x: 0x%x",
335 dest_addr, val);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200336 wl1271_write32(wl, dest_addr, val);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300337
338 nvs_ptr += 4;
339 dest_addr += 4;
340 }
341 }
342
343 /*
344 * We've reached the first zero length, the first NVS table
Ido Yariv67e02082010-09-22 09:53:13 +0200345 * is located at an aligned offset which is at least 7 bytes further.
Shahar Levibc765bf2011-03-06 16:32:10 +0200346 * NOTE: The wl->nvs->nvs element must be first, in order to
347 * simplify the casting, we assume it is at the beginning of
348 * the wl->nvs structure.
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300349 */
Shahar Levibc765bf2011-03-06 16:32:10 +0200350 nvs_ptr = (u8 *)wl->nvs +
351 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
352 nvs_len -= nvs_ptr - (u8 *)wl->nvs;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300353
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354 /* Now we must set the partition correctly */
Juuso Oikarinen451de972009-10-12 15:08:46 +0300355 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300356
357 /* Copy the NVS tables to a new block to ensure alignment */
Ido Yariv67e02082010-09-22 09:53:13 +0200358 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
359 if (!nvs_aligned)
360 return -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300361
362 /* And finally we upload the NVS tables */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200363 wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300364
365 kfree(nvs_aligned);
366 return 0;
367}
368
369static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
370{
Teemu Paasikivi54f7e502010-02-22 08:38:22 +0200371 wl1271_enable_interrupts(wl);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200372 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
373 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
374 wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300375}
376
377static int wl1271_boot_soft_reset(struct wl1271 *wl)
378{
379 unsigned long timeout;
380 u32 boot_data;
381
382 /* perform soft reset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200383 wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300384
385 /* SOFT_RESET is self clearing */
386 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
387 while (1) {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200388 boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300389 wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
390 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
391 break;
392
393 if (time_after(jiffies, timeout)) {
394 /* 1.2 check pWhalBus->uSelfClearTime if the
395 * timeout was reached */
396 wl1271_error("soft reset timeout");
397 return -1;
398 }
399
400 udelay(SOFT_RESET_STALL_TIME);
401 }
402
403 /* disable Rx/Tx */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200404 wl1271_write32(wl, ENABLE, 0x0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300405
406 /* disable auto calibration on start*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200407 wl1271_write32(wl, SPARE_A2, 0xffff);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300408
409 return 0;
410}
411
412static int wl1271_boot_run_firmware(struct wl1271 *wl)
413{
414 int loop, ret;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300415 u32 chip_id, intr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300416
417 wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
418
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200419 chip_id = wl1271_read32(wl, CHIP_ID_B);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300420
421 wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
422
423 if (chip_id != wl->chip.id) {
424 wl1271_error("chip id doesn't match after firmware boot");
425 return -EIO;
426 }
427
428 /* wait for init to complete */
429 loop = 0;
430 while (loop++ < INIT_LOOP) {
431 udelay(INIT_LOOP_DELAY);
Luciano Coelho23a7a512010-04-28 09:50:02 +0300432 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300433
Luciano Coelho23a7a512010-04-28 09:50:02 +0300434 if (intr == 0xffffffff) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300435 wl1271_error("error reading hardware complete "
436 "init indication");
437 return -EIO;
438 }
439 /* check that ACX_INTR_INIT_COMPLETE is enabled */
Luciano Coelho23a7a512010-04-28 09:50:02 +0300440 else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200441 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
442 WL1271_ACX_INTR_INIT_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300443 break;
444 }
445 }
446
Luciano Coelhoe7d17cf2009-10-29 13:20:04 +0200447 if (loop > INIT_LOOP) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300448 wl1271_error("timeout waiting for the hardware to "
449 "complete initialization");
450 return -EIO;
451 }
452
453 /* get hardware config command mail box */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200454 wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300455
456 /* get hardware config event mail box */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200457 wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300458
459 /* set the working partition to its "running" mode offset */
Juuso Oikarinen451de972009-10-12 15:08:46 +0300460 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300461
462 wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
463 wl->cmd_box_addr, wl->event_box_addr);
464
465 wl1271_boot_fw_version(wl);
466
467 /*
468 * in case of full asynchronous mode the firmware event must be
469 * ready to receive event from the command mailbox
470 */
471
Juuso Oikarinenbe823e52009-10-08 21:56:36 +0300472 /* unmask required mbox events */
473 wl->event_mask = BSS_LOSE_EVENT_ID |
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200474 SCAN_COMPLETE_EVENT_ID |
Luciano Coelho99d84c12010-03-26 12:53:20 +0200475 PS_REPORT_EVENT_ID |
Luciano Coelho2f826f52010-03-26 12:53:21 +0200476 JOIN_EVENT_COMPLETE_ID |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300477 DISCONNECT_EVENT_COMPLETE_ID |
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300478 RSSI_SNR_TRIGGER_0_EVENT_ID |
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300479 PSPOLL_DELIVERY_FAILURE_EVENT_ID |
480 SOFT_GEMINI_SENSE_EVENT_ID;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300481
Arik Nemtsov203c9032010-10-25 11:17:44 +0200482 if (wl->bss_type == BSS_TYPE_AP_BSS)
483 wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID;
484
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300485 ret = wl1271_event_unmask(wl);
486 if (ret < 0) {
487 wl1271_error("EVENT mask setting failed");
488 return ret;
489 }
490
491 wl1271_event_mbox_config(wl);
492
493 /* firmware startup completed */
494 return 0;
495}
496
497static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
498{
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300499 u32 polarity;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300500
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300501 polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300502
503 /* We use HIGH polarity, so unset the LOW bit */
504 polarity &= ~POLARITY_LOW;
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300505 wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300506
507 return 0;
508}
509
Juuso Oikarinend717fd62010-05-07 11:38:58 +0300510static void wl1271_boot_hw_version(struct wl1271 *wl)
511{
512 u32 fuse;
513
514 fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1);
515 fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET;
516
517 wl->hw_pg_ver = (s8)fuse;
Ido Yariv606ea9f2011-03-01 15:14:39 +0200518
519 if (((wl->hw_pg_ver & PG_MAJOR_VER_MASK) >> PG_MAJOR_VER_OFFSET) < 3)
520 wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
Juuso Oikarinend717fd62010-05-07 11:38:58 +0300521}
522
Roger Quadros870c3672010-11-29 16:24:57 +0200523/* uploads NVS and firmware */
524int wl1271_load_firmware(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300525{
526 int ret = 0;
527 u32 tmp, clk, pause;
528
Juuso Oikarinend717fd62010-05-07 11:38:58 +0300529 wl1271_boot_hw_version(wl);
530
Gery Kahnc8aea562010-10-05 16:09:05 +0200531 if (wl->ref_clock == 0 || wl->ref_clock == 2 || wl->ref_clock == 4)
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300532 /* ref clk: 19.2/38.4/38.4-XTAL */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300533 clk = 0x3;
Gery Kahnc8aea562010-10-05 16:09:05 +0200534 else if (wl->ref_clock == 1 || wl->ref_clock == 3)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300535 /* ref clk: 26/52 */
536 clk = 0x5;
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200537 else
538 return -EINVAL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300539
Gery Kahnc8aea562010-10-05 16:09:05 +0200540 if (wl->ref_clock != 0) {
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300541 u16 val;
Juuso Oikarinen9d4e5bb2010-03-26 12:53:15 +0200542 /* Set clock type (open drain) */
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300543 val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
544 val &= FREF_CLK_TYPE_BITS;
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300545 wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
Juuso Oikarinen9d4e5bb2010-03-26 12:53:15 +0200546
547 /* Set clock pull mode (no pull) */
548 val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL);
549 val |= NO_PULL;
550 wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val);
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300551 } else {
552 u16 val;
553 /* Set clock polarity */
554 val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
555 val &= FREF_CLK_POLARITY_BITS;
556 val |= CLK_REQ_OUTN_SEL;
557 wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
558 }
559
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200560 wl1271_write32(wl, PLL_PARAMETERS, clk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300561
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200562 pause = wl1271_read32(wl, PLL_PARAMETERS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300563
564 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
565
Juuso Oikarinen2f63b012010-08-10 06:38:35 +0200566 pause &= ~(WU_COUNTER_PAUSE_VAL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300567 pause |= WU_COUNTER_PAUSE_VAL;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200568 wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300569
570 /* Continue the ELP wake up sequence */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200571 wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300572 udelay(500);
573
Juuso Oikarinen451de972009-10-12 15:08:46 +0300574 wl1271_set_partition(wl, &part_table[PART_DRPW]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300575
576 /* Read-modify-write DRPW_SCRATCH_START register (see next state)
577 to be used by DRPw FW. The RTRIM value will be added by the FW
578 before taking DRPw out of reset */
579
580 wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200581 clk = wl1271_read32(wl, DRPW_SCRATCH_START);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300582
583 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
584
Gery Kahnc8aea562010-10-05 16:09:05 +0200585 clk |= (wl->ref_clock << 1) << 4;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200586 wl1271_write32(wl, DRPW_SCRATCH_START, clk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300587
Juuso Oikarinen451de972009-10-12 15:08:46 +0300588 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300589
590 /* Disable interrupts */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200591 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300592
593 ret = wl1271_boot_soft_reset(wl);
594 if (ret < 0)
595 goto out;
596
597 /* 2. start processing NVS file */
598 ret = wl1271_boot_upload_nvs(wl);
599 if (ret < 0)
600 goto out;
601
602 /* write firmware's last address (ie. it's length) to
603 * ACX_EEPROMLESS_IND_REG */
604 wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
605
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200606 wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300607
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200608 tmp = wl1271_read32(wl, CHIP_ID_B);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300609
610 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
611
612 /* 6. read the EEPROM parameters */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200613 tmp = wl1271_read32(wl, SCR_PAD2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300614
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300615 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
616 * to upload_fw) */
617
618 ret = wl1271_boot_upload_firmware(wl);
619 if (ret < 0)
620 goto out;
621
Roger Quadros870c3672010-11-29 16:24:57 +0200622out:
623 return ret;
624}
625EXPORT_SYMBOL_GPL(wl1271_load_firmware);
626
627int wl1271_boot(struct wl1271 *wl)
628{
629 int ret;
630
631 /* upload NVS and firmware */
632 ret = wl1271_load_firmware(wl);
633 if (ret)
634 return ret;
635
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300636 /* 10.5 start firmware */
637 ret = wl1271_boot_run_firmware(wl);
638 if (ret < 0)
639 goto out;
640
Shahar Levib9b0fde2011-03-06 16:32:06 +0200641 ret = wl1271_boot_write_irq_polarity(wl);
642 if (ret < 0)
643 goto out;
644
645 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
646 WL1271_ACX_ALL_EVENTS_VECTOR);
647
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +0300648 /* Enable firmware interrupts now */
649 wl1271_boot_enable_interrupts(wl);
650
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300651 /* set the wl1271 default filters */
Arik Nemtsovae113b52010-10-16 18:45:07 +0200652 wl1271_set_default_filters(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300653
654 wl1271_event_mbox_config(wl);
655
656out:
657 return ret;
658}