boot.c 14.6 KB
Newer Older
L
Luciano Coelho 已提交
1 2 3
/*
 * This file is part of wl1271
 *
4
 * Copyright (C) 2008-2010 Nokia Corporation
L
Luciano Coelho 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

24
#include <linux/slab.h>
L
Luciano Coelho 已提交
25

S
Shahar Levi 已提交
26 27 28 29 30
#include "acx.h"
#include "reg.h"
#include "boot.h"
#include "io.h"
#include "event.h"
31
#include "rx.h"
L
Luciano Coelho 已提交
32 33 34 35 36 37 38 39 40 41 42

static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
	[PART_DOWN] = {
		.mem = {
			.start = 0x00000000,
			.size  = 0x000177c0
		},
		.reg = {
			.start = REGISTERS_BASE,
			.size  = 0x00008800
		},
43 44 45 46 47 48 49 50
		.mem2 = {
			.start = 0x00000000,
			.size  = 0x00000000
		},
		.mem3 = {
			.start = 0x00000000,
			.size  = 0x00000000
		},
L
Luciano Coelho 已提交
51 52 53 54 55 56 57 58 59
	},

	[PART_WORK] = {
		.mem = {
			.start = 0x00040000,
			.size  = 0x00014fc0
		},
		.reg = {
			.start = REGISTERS_BASE,
60 61 62 63 64 65 66 67 68
			.size  = 0x0000a000
		},
		.mem2 = {
			.start = 0x003004f8,
			.size  = 0x00000004
		},
		.mem3 = {
			.start = 0x00040404,
			.size  = 0x00000000
L
Luciano Coelho 已提交
69 70 71 72 73 74 75 76 77 78 79
		},
	},

	[PART_DRPW] = {
		.mem = {
			.start = 0x00040000,
			.size  = 0x00014fc0
		},
		.reg = {
			.start = DRPW_BASE,
			.size  = 0x00006000
80 81 82 83 84 85 86 87
		},
		.mem2 = {
			.start = 0x00000000,
			.size  = 0x00000000
		},
		.mem3 = {
			.start = 0x00000000,
			.size  = 0x00000000
L
Luciano Coelho 已提交
88 89 90 91 92 93 94 95 96
		}
	}
};

static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
{
	u32 cpu_ctrl;

	/* 10.5.0 run the firmware (I) */
T
Teemu Paasikivi 已提交
97
	cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL);
L
Luciano Coelho 已提交
98 99 100

	/* 10.5.1 run the firmware (II) */
	cpu_ctrl |= flag;
T
Teemu Paasikivi 已提交
101
	wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
L
Luciano Coelho 已提交
102 103 104 105 106 107
}

static void wl1271_boot_fw_version(struct wl1271 *wl)
{
	struct wl1271_static_data static_data;

T
Teemu Paasikivi 已提交
108 109
	wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
		    false);
L
Luciano Coelho 已提交
110 111 112 113 114 115 116 117 118 119 120

	strncpy(wl->chip.fw_ver, static_data.fw_version,
		sizeof(wl->chip.fw_ver));

	/* make sure the string is NULL-terminated */
	wl->chip.fw_ver[sizeof(wl->chip.fw_ver) - 1] = '\0';
}

static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
					     size_t fw_data_len, u32 dest)
{
121
	struct wl1271_partition_set partition;
L
Luciano Coelho 已提交
122
	int addr, chunk_num, partition_limit;
123
	u8 *p, *chunk;
L
Luciano Coelho 已提交
124 125 126 127 128

	/* whal_FwCtrl_LoadFwImageSm() */

	wl1271_debug(DEBUG_BOOT, "starting firmware upload");

129 130
	wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
		     fw_data_len, CHUNK_SIZE);
L
Luciano Coelho 已提交
131 132 133 134 135 136

	if ((fw_data_len % 4) != 0) {
		wl1271_error("firmware length not multiple of four");
		return -EIO;
	}

137
	chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
138
	if (!chunk) {
139 140 141 142
		wl1271_error("allocation for firmware upload chunk failed");
		return -ENOMEM;
	}

143 144 145
	memcpy(&partition, &part_table[PART_DOWN], sizeof(partition));
	partition.mem.start = dest;
	wl1271_set_partition(wl, &partition);
L
Luciano Coelho 已提交
146 147 148 149 150 151 152 153 154 155 156 157

	/* 10.1 set partition limit and chunk num */
	chunk_num = 0;
	partition_limit = part_table[PART_DOWN].mem.size;

	while (chunk_num < fw_data_len / CHUNK_SIZE) {
		/* 10.2 update partition, if needed */
		addr = dest + (chunk_num + 2) * CHUNK_SIZE;
		if (addr > partition_limit) {
			addr = dest + chunk_num * CHUNK_SIZE;
			partition_limit = chunk_num * CHUNK_SIZE +
				part_table[PART_DOWN].mem.size;
158 159
			partition.mem.start = addr;
			wl1271_set_partition(wl, &partition);
L
Luciano Coelho 已提交
160 161 162 163 164
		}

		/* 10.3 upload the chunk */
		addr = dest + chunk_num * CHUNK_SIZE;
		p = buf + chunk_num * CHUNK_SIZE;
165
		memcpy(chunk, p, CHUNK_SIZE);
L
Luciano Coelho 已提交
166 167
		wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
			     p, addr);
T
Teemu Paasikivi 已提交
168
		wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
L
Luciano Coelho 已提交
169 170 171 172 173 174 175

		chunk_num++;
	}

	/* 10.4 upload the last chunk */
	addr = dest + chunk_num * CHUNK_SIZE;
	p = buf + chunk_num * CHUNK_SIZE;
176
	memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
177
	wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
L
Luciano Coelho 已提交
178
		     fw_data_len % CHUNK_SIZE, p, addr);
T
Teemu Paasikivi 已提交
179
	wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
L
Luciano Coelho 已提交
180

181
	kfree(chunk);
L
Luciano Coelho 已提交
182 183 184 185 186 187
	return 0;
}

static int wl1271_boot_upload_firmware(struct wl1271 *wl)
{
	u32 chunks, addr, len;
188
	int ret = 0;
L
Luciano Coelho 已提交
189 190 191
	u8 *fw;

	fw = wl->fw;
L
Luciano Coelho 已提交
192
	chunks = be32_to_cpup((__be32 *) fw);
L
Luciano Coelho 已提交
193 194 195 196 197
	fw += sizeof(u32);

	wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);

	while (chunks--) {
L
Luciano Coelho 已提交
198
		addr = be32_to_cpup((__be32 *) fw);
L
Luciano Coelho 已提交
199
		fw += sizeof(u32);
L
Luciano Coelho 已提交
200
		len = be32_to_cpup((__be32 *) fw);
L
Luciano Coelho 已提交
201 202 203 204 205 206 207 208
		fw += sizeof(u32);

		if (len > 300000) {
			wl1271_info("firmware chunk too long: %u", len);
			return -EINVAL;
		}
		wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
			     chunks, addr, len);
209 210 211
		ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
		if (ret != 0)
			break;
L
Luciano Coelho 已提交
212 213 214
		fw += len;
	}

215
	return ret;
L
Luciano Coelho 已提交
216 217 218 219 220 221 222
}

static int wl1271_boot_upload_nvs(struct wl1271 *wl)
{
	size_t nvs_len, burst_len;
	int i;
	u32 dest_addr, val;
223
	u8 *nvs_ptr, *nvs_aligned;
L
Luciano Coelho 已提交
224

225
	if (wl->nvs == NULL)
L
Luciano Coelho 已提交
226 227
		return -ENODEV;

228 229 230 231 232 233 234
	/*
	 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz band
	 * configurations) can be removed when those NVS files stop floating
	 * around.
	 */
	if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
	    wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
A
Arik Nemtsov 已提交
235 236 237
		/* for now 11a is unsupported in AP mode */
		if (wl->bss_type != BSS_TYPE_AP_BSS &&
		    wl->nvs->general_params.dual_mode_select)
238 239 240 241 242 243 244 245 246 247 248 249 250 251
			wl->enable_11a = true;
	}

	if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
	    (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
	     wl->enable_11a)) {
		wl1271_error("nvs size is not as expected: %zu != %zu",
			     wl->nvs_len, sizeof(struct wl1271_nvs_file));
		kfree(wl->nvs);
		wl->nvs = NULL;
		wl->nvs_len = 0;
		return -EILSEQ;
	}

252
	/* only the first part of the NVS needs to be uploaded */
253 254
	nvs_len = sizeof(wl->nvs->nvs);
	nvs_ptr = (u8 *)wl->nvs->nvs;
L
Luciano Coelho 已提交
255

256 257 258 259 260 261 262 263
	/* update current MAC address to NVS */
	nvs_ptr[11] = wl->mac_addr[0];
	nvs_ptr[10] = wl->mac_addr[1];
	nvs_ptr[6] = wl->mac_addr[2];
	nvs_ptr[5] = wl->mac_addr[3];
	nvs_ptr[4] = wl->mac_addr[4];
	nvs_ptr[3] = wl->mac_addr[5];

L
Luciano Coelho 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277
	/*
	 * Layout before the actual NVS tables:
	 * 1 byte : burst length.
	 * 2 bytes: destination address.
	 * n bytes: data to burst copy.
	 *
	 * This is ended by a 0 length, then the NVS tables.
	 */

	/* FIXME: Do we need to check here whether the LSB is 1? */
	while (nvs_ptr[0]) {
		burst_len = nvs_ptr[0];
		dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));

278 279 280 281
		/*
		 * Due to our new wl1271_translate_reg_addr function,
		 * we need to add the REGISTER_BASE to the destination
		 */
L
Luciano Coelho 已提交
282 283 284 285 286 287 288 289 290 291 292 293
		dest_addr += REGISTERS_BASE;

		/* We move our pointer to the data */
		nvs_ptr += 3;

		for (i = 0; i < burst_len; i++) {
			val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
			       | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));

			wl1271_debug(DEBUG_BOOT,
				     "nvs burst write 0x%x: 0x%x",
				     dest_addr, val);
T
Teemu Paasikivi 已提交
294
			wl1271_write32(wl, dest_addr, val);
L
Luciano Coelho 已提交
295 296 297 298 299 300 301 302

			nvs_ptr += 4;
			dest_addr += 4;
		}
	}

	/*
	 * We've reached the first zero length, the first NVS table
303
	 * is located at an aligned offset which is at least 7 bytes further.
L
Luciano Coelho 已提交
304
	 */
305 306
	nvs_ptr = (u8 *)wl->nvs->nvs +
			ALIGN(nvs_ptr - (u8 *)wl->nvs->nvs + 7, 4);
307
	nvs_len -= nvs_ptr - (u8 *)wl->nvs->nvs;
L
Luciano Coelho 已提交
308 309

	/* Now we must set the partition correctly */
310
	wl1271_set_partition(wl, &part_table[PART_WORK]);
L
Luciano Coelho 已提交
311 312

	/* Copy the NVS tables to a new block to ensure alignment */
313 314 315
	nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
	if (!nvs_aligned)
		return -ENOMEM;
L
Luciano Coelho 已提交
316 317

	/* And finally we upload the NVS tables */
T
Teemu Paasikivi 已提交
318
	wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
L
Luciano Coelho 已提交
319 320 321 322 323 324 325

	kfree(nvs_aligned);
	return 0;
}

static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
{
326
	wl1271_enable_interrupts(wl);
T
Teemu Paasikivi 已提交
327 328 329
	wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
		       WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
	wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
L
Luciano Coelho 已提交
330 331 332 333 334 335 336 337
}

static int wl1271_boot_soft_reset(struct wl1271 *wl)
{
	unsigned long timeout;
	u32 boot_data;

	/* perform soft reset */
T
Teemu Paasikivi 已提交
338
	wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
L
Luciano Coelho 已提交
339 340 341 342

	/* SOFT_RESET is self clearing */
	timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
	while (1) {
T
Teemu Paasikivi 已提交
343
		boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
L
Luciano Coelho 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
		wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
		if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
			break;

		if (time_after(jiffies, timeout)) {
			/* 1.2 check pWhalBus->uSelfClearTime if the
			 * timeout was reached */
			wl1271_error("soft reset timeout");
			return -1;
		}

		udelay(SOFT_RESET_STALL_TIME);
	}

	/* disable Rx/Tx */
T
Teemu Paasikivi 已提交
359
	wl1271_write32(wl, ENABLE, 0x0);
L
Luciano Coelho 已提交
360 361

	/* disable auto calibration on start*/
T
Teemu Paasikivi 已提交
362
	wl1271_write32(wl, SPARE_A2, 0xffff);
L
Luciano Coelho 已提交
363 364 365 366 367 368 369

	return 0;
}

static int wl1271_boot_run_firmware(struct wl1271 *wl)
{
	int loop, ret;
370
	u32 chip_id, intr;
L
Luciano Coelho 已提交
371 372 373

	wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);

T
Teemu Paasikivi 已提交
374
	chip_id = wl1271_read32(wl, CHIP_ID_B);
L
Luciano Coelho 已提交
375 376 377 378 379 380 381 382 383 384 385 386

	wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);

	if (chip_id != wl->chip.id) {
		wl1271_error("chip id doesn't match after firmware boot");
		return -EIO;
	}

	/* wait for init to complete */
	loop = 0;
	while (loop++ < INIT_LOOP) {
		udelay(INIT_LOOP_DELAY);
387
		intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
L
Luciano Coelho 已提交
388

389
		if (intr == 0xffffffff) {
L
Luciano Coelho 已提交
390 391 392 393 394
			wl1271_error("error reading hardware complete "
				     "init indication");
			return -EIO;
		}
		/* check that ACX_INTR_INIT_COMPLETE is enabled */
395
		else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
T
Teemu Paasikivi 已提交
396 397
			wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
				       WL1271_ACX_INTR_INIT_COMPLETE);
L
Luciano Coelho 已提交
398 399 400 401
			break;
		}
	}

L
Luciano Coelho 已提交
402
	if (loop > INIT_LOOP) {
L
Luciano Coelho 已提交
403 404 405 406 407 408
		wl1271_error("timeout waiting for the hardware to "
			     "complete initialization");
		return -EIO;
	}

	/* get hardware config command mail box */
T
Teemu Paasikivi 已提交
409
	wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
L
Luciano Coelho 已提交
410 411

	/* get hardware config event mail box */
T
Teemu Paasikivi 已提交
412
	wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
L
Luciano Coelho 已提交
413 414

	/* set the working partition to its "running" mode offset */
415
	wl1271_set_partition(wl, &part_table[PART_WORK]);
L
Luciano Coelho 已提交
416 417 418 419 420 421 422 423 424 425 426

	wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
		     wl->cmd_box_addr, wl->event_box_addr);

	wl1271_boot_fw_version(wl);

	/*
	 * in case of full asynchronous mode the firmware event must be
	 * ready to receive event from the command mailbox
	 */

427 428
	/* unmask required mbox events  */
	wl->event_mask = BSS_LOSE_EVENT_ID |
429
		SCAN_COMPLETE_EVENT_ID |
430
		PS_REPORT_EVENT_ID |
431
		JOIN_EVENT_COMPLETE_ID |
432
		DISCONNECT_EVENT_COMPLETE_ID |
433
		RSSI_SNR_TRIGGER_0_EVENT_ID |
434 435
		PSPOLL_DELIVERY_FAILURE_EVENT_ID |
		SOFT_GEMINI_SENSE_EVENT_ID;
L
Luciano Coelho 已提交
436

437 438 439
	if (wl->bss_type == BSS_TYPE_AP_BSS)
		wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID;

L
Luciano Coelho 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453
	ret = wl1271_event_unmask(wl);
	if (ret < 0) {
		wl1271_error("EVENT mask setting failed");
		return ret;
	}

	wl1271_event_mbox_config(wl);

	/* firmware startup completed */
	return 0;
}

static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
{
454
	u32 polarity;
L
Luciano Coelho 已提交
455

456
	polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
L
Luciano Coelho 已提交
457 458 459

	/* We use HIGH polarity, so unset the LOW bit */
	polarity &= ~POLARITY_LOW;
460
	wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
L
Luciano Coelho 已提交
461 462 463 464

	return 0;
}

465 466 467 468 469 470 471 472 473 474
static void wl1271_boot_hw_version(struct wl1271 *wl)
{
	u32 fuse;

	fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1);
	fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET;

	wl->hw_pg_ver = (s8)fuse;
}

475 476
/* uploads NVS and firmware */
int wl1271_load_firmware(struct wl1271 *wl)
L
Luciano Coelho 已提交
477 478 479 480
{
	int ret = 0;
	u32 tmp, clk, pause;

481 482
	wl1271_boot_hw_version(wl);

G
Gery Kahn 已提交
483
	if (wl->ref_clock == 0 || wl->ref_clock == 2 || wl->ref_clock == 4)
J
Juuso Oikarinen 已提交
484
		/* ref clk: 19.2/38.4/38.4-XTAL */
L
Luciano Coelho 已提交
485
		clk = 0x3;
G
Gery Kahn 已提交
486
	else if (wl->ref_clock == 1 || wl->ref_clock == 3)
L
Luciano Coelho 已提交
487 488
		/* ref clk: 26/52 */
		clk = 0x5;
489 490
	else
		return -EINVAL;
L
Luciano Coelho 已提交
491

G
Gery Kahn 已提交
492
	if (wl->ref_clock != 0) {
J
Juuso Oikarinen 已提交
493
		u16 val;
494
		/* Set clock type (open drain) */
J
Juuso Oikarinen 已提交
495 496 497
		val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
		val &= FREF_CLK_TYPE_BITS;
		wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
498 499 500 501 502

		/* Set clock pull mode (no pull) */
		val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL);
		val |= NO_PULL;
		wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val);
J
Juuso Oikarinen 已提交
503 504 505 506 507 508 509 510 511
	} else {
		u16 val;
		/* Set clock polarity */
		val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
		val &= FREF_CLK_POLARITY_BITS;
		val |= CLK_REQ_OUTN_SEL;
		wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
	}

T
Teemu Paasikivi 已提交
512
	wl1271_write32(wl, PLL_PARAMETERS, clk);
L
Luciano Coelho 已提交
513

T
Teemu Paasikivi 已提交
514
	pause = wl1271_read32(wl, PLL_PARAMETERS);
L
Luciano Coelho 已提交
515 516 517

	wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);

518
	pause &= ~(WU_COUNTER_PAUSE_VAL);
L
Luciano Coelho 已提交
519
	pause |= WU_COUNTER_PAUSE_VAL;
T
Teemu Paasikivi 已提交
520
	wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
L
Luciano Coelho 已提交
521 522

	/* Continue the ELP wake up sequence */
T
Teemu Paasikivi 已提交
523
	wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
L
Luciano Coelho 已提交
524 525
	udelay(500);

526
	wl1271_set_partition(wl, &part_table[PART_DRPW]);
L
Luciano Coelho 已提交
527 528 529 530 531 532

	/* Read-modify-write DRPW_SCRATCH_START register (see next state)
	   to be used by DRPw FW. The RTRIM value will be added by the FW
	   before taking DRPw out of reset */

	wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
T
Teemu Paasikivi 已提交
533
	clk = wl1271_read32(wl, DRPW_SCRATCH_START);
L
Luciano Coelho 已提交
534 535 536

	wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);

G
Gery Kahn 已提交
537
	clk |= (wl->ref_clock << 1) << 4;
T
Teemu Paasikivi 已提交
538
	wl1271_write32(wl, DRPW_SCRATCH_START, clk);
L
Luciano Coelho 已提交
539

540
	wl1271_set_partition(wl, &part_table[PART_WORK]);
L
Luciano Coelho 已提交
541 542

	/* Disable interrupts */
T
Teemu Paasikivi 已提交
543
	wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
L
Luciano Coelho 已提交
544 545 546 547 548 549 550 551 552 553 554 555 556 557

	ret = wl1271_boot_soft_reset(wl);
	if (ret < 0)
		goto out;

	/* 2. start processing NVS file */
	ret = wl1271_boot_upload_nvs(wl);
	if (ret < 0)
		goto out;

	/* write firmware's last address (ie. it's length) to
	 * ACX_EEPROMLESS_IND_REG */
	wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");

T
Teemu Paasikivi 已提交
558
	wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
L
Luciano Coelho 已提交
559

T
Teemu Paasikivi 已提交
560
	tmp = wl1271_read32(wl, CHIP_ID_B);
L
Luciano Coelho 已提交
561 562 563 564

	wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);

	/* 6. read the EEPROM parameters */
T
Teemu Paasikivi 已提交
565
	tmp = wl1271_read32(wl, SCR_PAD2);
L
Luciano Coelho 已提交
566 567 568 569 570

	ret = wl1271_boot_write_irq_polarity(wl);
	if (ret < 0)
		goto out;

T
Teemu Paasikivi 已提交
571 572
	wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
		       WL1271_ACX_ALL_EVENTS_VECTOR);
L
Luciano Coelho 已提交
573 574 575 576 577 578 579 580

	/* WL1271: The reference driver skips steps 7 to 10 (jumps directly
	 * to upload_fw) */

	ret = wl1271_boot_upload_firmware(wl);
	if (ret < 0)
		goto out;

581 582 583 584 585 586 587 588 589 590 591 592 593 594
out:
	return ret;
}
EXPORT_SYMBOL_GPL(wl1271_load_firmware);

int wl1271_boot(struct wl1271 *wl)
{
	int ret;

	/* upload NVS and firmware */
	ret = wl1271_load_firmware(wl);
	if (ret)
		return ret;

L
Luciano Coelho 已提交
595 596 597 598 599
	/* 10.5 start firmware */
	ret = wl1271_boot_run_firmware(wl);
	if (ret < 0)
		goto out;

600 601 602
	/* Enable firmware interrupts now */
	wl1271_boot_enable_interrupts(wl);

L
Luciano Coelho 已提交
603
	/* set the wl1271 default filters */
604
	wl1271_set_default_filters(wl);
L
Luciano Coelho 已提交
605 606 607 608 609 610

	wl1271_event_mbox_config(wl);

out:
	return ret;
}