blob: e5a7f042645f0a8dc8d7e76c9c3371c66d67ac81 [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
24#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030026
27#include "wl1271_acx.h"
28#include "wl1271_reg.h"
29#include "wl1271_boot.h"
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020030#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030031#include "wl1271_event.h"
32
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
104static void wl1271_boot_fw_version(struct wl1271 *wl)
105{
106 struct wl1271_static_data static_data;
107
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200108 wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
109 false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300110
111 strncpy(wl->chip.fw_ver, static_data.fw_version,
112 sizeof(wl->chip.fw_ver));
113
114 /* make sure the string is NULL-terminated */
115 wl->chip.fw_ver[sizeof(wl->chip.fw_ver) - 1] = '\0';
116}
117
118static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
119 size_t fw_data_len, u32 dest)
120{
Juuso Oikarinen451de972009-10-12 15:08:46 +0300121 struct wl1271_partition_set partition;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300122 int addr, chunk_num, partition_limit;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300123 u8 *p, *chunk;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300124
125 /* whal_FwCtrl_LoadFwImageSm() */
126
127 wl1271_debug(DEBUG_BOOT, "starting firmware upload");
128
Luciano Coelho73d0a132009-08-11 11:58:27 +0300129 wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
130 fw_data_len, CHUNK_SIZE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300131
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300132 if ((fw_data_len % 4) != 0) {
133 wl1271_error("firmware length not multiple of four");
134 return -EIO;
135 }
136
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300137 chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
Juuso Oikarinened3177882009-10-13 12:47:57 +0300138 if (!chunk) {
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300139 wl1271_error("allocation for firmware upload chunk failed");
140 return -ENOMEM;
141 }
142
Juuso Oikarinen451de972009-10-12 15:08:46 +0300143 memcpy(&partition, &part_table[PART_DOWN], sizeof(partition));
144 partition.mem.start = dest;
145 wl1271_set_partition(wl, &partition);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300146
147 /* 10.1 set partition limit and chunk num */
148 chunk_num = 0;
149 partition_limit = part_table[PART_DOWN].mem.size;
150
151 while (chunk_num < fw_data_len / CHUNK_SIZE) {
152 /* 10.2 update partition, if needed */
153 addr = dest + (chunk_num + 2) * CHUNK_SIZE;
154 if (addr > partition_limit) {
155 addr = dest + chunk_num * CHUNK_SIZE;
156 partition_limit = chunk_num * CHUNK_SIZE +
157 part_table[PART_DOWN].mem.size;
Juuso Oikarinen451de972009-10-12 15:08:46 +0300158 partition.mem.start = addr;
159 wl1271_set_partition(wl, &partition);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300160 }
161
162 /* 10.3 upload the chunk */
163 addr = dest + chunk_num * CHUNK_SIZE;
164 p = buf + chunk_num * CHUNK_SIZE;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300165 memcpy(chunk, p, CHUNK_SIZE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300166 wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
167 p, addr);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200168 wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300169
170 chunk_num++;
171 }
172
173 /* 10.4 upload the last chunk */
174 addr = dest + chunk_num * CHUNK_SIZE;
175 p = buf + chunk_num * CHUNK_SIZE;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300176 memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
Luciano Coelho73d0a132009-08-11 11:58:27 +0300177 wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300178 fw_data_len % CHUNK_SIZE, p, addr);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200179 wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300180
Juuso Oikarinen1fba4972009-10-08 21:56:32 +0300181 kfree(chunk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300182 return 0;
183}
184
185static int wl1271_boot_upload_firmware(struct wl1271 *wl)
186{
187 u32 chunks, addr, len;
Juuso Oikarinened3177882009-10-13 12:47:57 +0300188 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300189 u8 *fw;
190
191 fw = wl->fw;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300192 chunks = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300193 fw += sizeof(u32);
194
195 wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
196
197 while (chunks--) {
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300198 addr = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300199 fw += sizeof(u32);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300200 len = be32_to_cpup((__be32 *) fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300201 fw += sizeof(u32);
202
203 if (len > 300000) {
204 wl1271_info("firmware chunk too long: %u", len);
205 return -EINVAL;
206 }
207 wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
208 chunks, addr, len);
Juuso Oikarinened3177882009-10-13 12:47:57 +0300209 ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
210 if (ret != 0)
211 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300212 fw += len;
213 }
214
Juuso Oikarinened3177882009-10-13 12:47:57 +0300215 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300216}
217
218static int wl1271_boot_upload_nvs(struct wl1271 *wl)
219{
220 size_t nvs_len, burst_len;
221 int i;
222 u32 dest_addr, val;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200223 u8 *nvs_ptr, *nvs_aligned;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300224
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200225 if (wl->nvs == NULL)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300226 return -ENODEV;
227
Luciano Coelho8cf5e8e2009-12-11 15:40:53 +0200228 /* only the first part of the NVS needs to be uploaded */
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200229 nvs_len = sizeof(wl->nvs->nvs);
230 nvs_ptr = (u8 *)wl->nvs->nvs;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300231
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +0200232 /* update current MAC address to NVS */
233 nvs_ptr[11] = wl->mac_addr[0];
234 nvs_ptr[10] = wl->mac_addr[1];
235 nvs_ptr[6] = wl->mac_addr[2];
236 nvs_ptr[5] = wl->mac_addr[3];
237 nvs_ptr[4] = wl->mac_addr[4];
238 nvs_ptr[3] = wl->mac_addr[5];
239
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300240 /*
241 * Layout before the actual NVS tables:
242 * 1 byte : burst length.
243 * 2 bytes: destination address.
244 * n bytes: data to burst copy.
245 *
246 * This is ended by a 0 length, then the NVS tables.
247 */
248
249 /* FIXME: Do we need to check here whether the LSB is 1? */
250 while (nvs_ptr[0]) {
251 burst_len = nvs_ptr[0];
252 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
253
254 /* FIXME: Due to our new wl1271_translate_reg_addr function,
255 we need to add the REGISTER_BASE to the destination */
256 dest_addr += REGISTERS_BASE;
257
258 /* We move our pointer to the data */
259 nvs_ptr += 3;
260
261 for (i = 0; i < burst_len; i++) {
262 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
263 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
264
265 wl1271_debug(DEBUG_BOOT,
266 "nvs burst write 0x%x: 0x%x",
267 dest_addr, val);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200268 wl1271_write32(wl, dest_addr, val);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300269
270 nvs_ptr += 4;
271 dest_addr += 4;
272 }
273 }
274
275 /*
276 * We've reached the first zero length, the first NVS table
Ido Yariv67e02082010-09-22 09:53:13 +0200277 * is located at an aligned offset which is at least 7 bytes further.
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300278 */
Ido Yariv67e02082010-09-22 09:53:13 +0200279 nvs_ptr = (u8 *)wl->nvs->nvs +
280 ALIGN(nvs_ptr - (u8 *)wl->nvs->nvs + 7, 4);
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200281 nvs_len -= nvs_ptr - (u8 *)wl->nvs->nvs;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282
283 /* FIXME: The driver sets the partition here, but this is not needed,
284 since it sets to the same one as currently in use */
285 /* Now we must set the partition correctly */
Juuso Oikarinen451de972009-10-12 15:08:46 +0300286 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300287
288 /* Copy the NVS tables to a new block to ensure alignment */
Ido Yariv67e02082010-09-22 09:53:13 +0200289 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
290 if (!nvs_aligned)
291 return -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300292
293 /* And finally we upload the NVS tables */
294 /* FIXME: In wl1271, we upload everything at once.
295 No endianness handling needed here?! The ref driver doesn't do
296 anything about it at this point */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200297 wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300298
299 kfree(nvs_aligned);
300 return 0;
301}
302
303static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
304{
Teemu Paasikivi54f7e502010-02-22 08:38:22 +0200305 wl1271_enable_interrupts(wl);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200306 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
307 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
308 wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300309}
310
311static int wl1271_boot_soft_reset(struct wl1271 *wl)
312{
313 unsigned long timeout;
314 u32 boot_data;
315
316 /* perform soft reset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200317 wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300318
319 /* SOFT_RESET is self clearing */
320 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
321 while (1) {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200322 boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300323 wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
324 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
325 break;
326
327 if (time_after(jiffies, timeout)) {
328 /* 1.2 check pWhalBus->uSelfClearTime if the
329 * timeout was reached */
330 wl1271_error("soft reset timeout");
331 return -1;
332 }
333
334 udelay(SOFT_RESET_STALL_TIME);
335 }
336
337 /* disable Rx/Tx */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200338 wl1271_write32(wl, ENABLE, 0x0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300339
340 /* disable auto calibration on start*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200341 wl1271_write32(wl, SPARE_A2, 0xffff);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300342
343 return 0;
344}
345
346static int wl1271_boot_run_firmware(struct wl1271 *wl)
347{
348 int loop, ret;
Luciano Coelho23a7a512010-04-28 09:50:02 +0300349 u32 chip_id, intr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300350
351 wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
352
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200353 chip_id = wl1271_read32(wl, CHIP_ID_B);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354
355 wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
356
357 if (chip_id != wl->chip.id) {
358 wl1271_error("chip id doesn't match after firmware boot");
359 return -EIO;
360 }
361
362 /* wait for init to complete */
363 loop = 0;
364 while (loop++ < INIT_LOOP) {
365 udelay(INIT_LOOP_DELAY);
Luciano Coelho23a7a512010-04-28 09:50:02 +0300366 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300367
Luciano Coelho23a7a512010-04-28 09:50:02 +0300368 if (intr == 0xffffffff) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300369 wl1271_error("error reading hardware complete "
370 "init indication");
371 return -EIO;
372 }
373 /* check that ACX_INTR_INIT_COMPLETE is enabled */
Luciano Coelho23a7a512010-04-28 09:50:02 +0300374 else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200375 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
376 WL1271_ACX_INTR_INIT_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300377 break;
378 }
379 }
380
Luciano Coelhoe7d17cf2009-10-29 13:20:04 +0200381 if (loop > INIT_LOOP) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300382 wl1271_error("timeout waiting for the hardware to "
383 "complete initialization");
384 return -EIO;
385 }
386
387 /* get hardware config command mail box */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200388 wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300389
390 /* get hardware config event mail box */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200391 wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300392
393 /* set the working partition to its "running" mode offset */
Juuso Oikarinen451de972009-10-12 15:08:46 +0300394 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395
396 wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
397 wl->cmd_box_addr, wl->event_box_addr);
398
399 wl1271_boot_fw_version(wl);
400
401 /*
402 * in case of full asynchronous mode the firmware event must be
403 * ready to receive event from the command mailbox
404 */
405
Juuso Oikarinenbe823e52009-10-08 21:56:36 +0300406 /* unmask required mbox events */
407 wl->event_mask = BSS_LOSE_EVENT_ID |
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200408 SCAN_COMPLETE_EVENT_ID |
Luciano Coelho99d84c12010-03-26 12:53:20 +0200409 PS_REPORT_EVENT_ID |
Luciano Coelho2f826f52010-03-26 12:53:21 +0200410 JOIN_EVENT_COMPLETE_ID |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300411 DISCONNECT_EVENT_COMPLETE_ID |
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300412 RSSI_SNR_TRIGGER_0_EVENT_ID |
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300413 PSPOLL_DELIVERY_FAILURE_EVENT_ID |
414 SOFT_GEMINI_SENSE_EVENT_ID;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300415
416 ret = wl1271_event_unmask(wl);
417 if (ret < 0) {
418 wl1271_error("EVENT mask setting failed");
419 return ret;
420 }
421
422 wl1271_event_mbox_config(wl);
423
424 /* firmware startup completed */
425 return 0;
426}
427
428static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
429{
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300430 u32 polarity;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300431
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300432 polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300433
434 /* We use HIGH polarity, so unset the LOW bit */
435 polarity &= ~POLARITY_LOW;
Juuso Oikarinene8768ee2009-10-12 15:08:48 +0300436 wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300437
438 return 0;
439}
440
Juuso Oikarinend717fd62010-05-07 11:38:58 +0300441static void wl1271_boot_hw_version(struct wl1271 *wl)
442{
443 u32 fuse;
444
445 fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1);
446 fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET;
447
448 wl->hw_pg_ver = (s8)fuse;
449}
450
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300451int wl1271_boot(struct wl1271 *wl)
452{
453 int ret = 0;
454 u32 tmp, clk, pause;
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200455 int ref_clock = wl->ref_clock;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300456
Juuso Oikarinend717fd62010-05-07 11:38:58 +0300457 wl1271_boot_hw_version(wl);
458
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200459 if (ref_clock == 0 || ref_clock == 2 || ref_clock == 4)
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300460 /* ref clk: 19.2/38.4/38.4-XTAL */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300461 clk = 0x3;
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200462 else if (ref_clock == 1 || ref_clock == 3)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300463 /* ref clk: 26/52 */
464 clk = 0x5;
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200465 else
466 return -EINVAL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300467
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200468 if (ref_clock != 0) {
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300469 u16 val;
Juuso Oikarinen9d4e5bb2010-03-26 12:53:15 +0200470 /* Set clock type (open drain) */
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300471 val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
472 val &= FREF_CLK_TYPE_BITS;
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300473 wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
Juuso Oikarinen9d4e5bb2010-03-26 12:53:15 +0200474
475 /* Set clock pull mode (no pull) */
476 val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL);
477 val |= NO_PULL;
478 wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val);
Juuso Oikarinen284134e2009-10-12 15:08:49 +0300479 } else {
480 u16 val;
481 /* Set clock polarity */
482 val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
483 val &= FREF_CLK_POLARITY_BITS;
484 val |= CLK_REQ_OUTN_SEL;
485 wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
486 }
487
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200488 wl1271_write32(wl, PLL_PARAMETERS, clk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300489
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200490 pause = wl1271_read32(wl, PLL_PARAMETERS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300491
492 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
493
494 pause &= ~(WU_COUNTER_PAUSE_VAL); /* FIXME: This should probably be
495 * WU_COUNTER_PAUSE_VAL instead of
496 * 0x3ff (magic number ). How does
497 * this work?! */
498 pause |= WU_COUNTER_PAUSE_VAL;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200499 wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300500
501 /* Continue the ELP wake up sequence */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200502 wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300503 udelay(500);
504
Juuso Oikarinen451de972009-10-12 15:08:46 +0300505 wl1271_set_partition(wl, &part_table[PART_DRPW]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300506
507 /* Read-modify-write DRPW_SCRATCH_START register (see next state)
508 to be used by DRPw FW. The RTRIM value will be added by the FW
509 before taking DRPw out of reset */
510
511 wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200512 clk = wl1271_read32(wl, DRPW_SCRATCH_START);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300513
514 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
515
516 /* 2 */
Ohad Ben-Cohen15cea992010-09-16 01:31:51 +0200517 clk |= (ref_clock << 1) << 4;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200518 wl1271_write32(wl, DRPW_SCRATCH_START, clk);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300519
Juuso Oikarinen451de972009-10-12 15:08:46 +0300520 wl1271_set_partition(wl, &part_table[PART_WORK]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300521
522 /* Disable interrupts */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200523 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300524
525 ret = wl1271_boot_soft_reset(wl);
526 if (ret < 0)
527 goto out;
528
529 /* 2. start processing NVS file */
530 ret = wl1271_boot_upload_nvs(wl);
531 if (ret < 0)
532 goto out;
533
534 /* write firmware's last address (ie. it's length) to
535 * ACX_EEPROMLESS_IND_REG */
536 wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
537
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200538 wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300539
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200540 tmp = wl1271_read32(wl, CHIP_ID_B);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300541
542 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
543
544 /* 6. read the EEPROM parameters */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200545 tmp = wl1271_read32(wl, SCR_PAD2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300546
547 ret = wl1271_boot_write_irq_polarity(wl);
548 if (ret < 0)
549 goto out;
550
551 /* FIXME: Need to check whether this is really what we want */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200552 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
553 WL1271_ACX_ALL_EVENTS_VECTOR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300554
555 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
556 * to upload_fw) */
557
558 ret = wl1271_boot_upload_firmware(wl);
559 if (ret < 0)
560 goto out;
561
562 /* 10.5 start firmware */
563 ret = wl1271_boot_run_firmware(wl);
564 if (ret < 0)
565 goto out;
566
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +0300567 /* Enable firmware interrupts now */
568 wl1271_boot_enable_interrupts(wl);
569
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300570 /* set the wl1271 default filters */
571 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
572 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
573
574 wl1271_event_mbox_config(wl);
575
576out:
577 return ret;
578}