wl1251_boot.c 8.0 KB
Newer Older
K
Kalle Valo 已提交
1
/*
2
 * This file is part of wl1251
K
Kalle Valo 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * Copyright (C) 2008 Nokia Corporation
 *
 * Contact: Kalle Valo <kalle.valo@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
 *
 */

#include <linux/gpio.h>

#include "reg.h"
27
#include "wl1251_boot.h"
28
#include "wl1251_io.h"
29
#include "wl1251_event.h"
K
Kalle Valo 已提交
30

31
static void wl1251_boot_enable_interrupts(struct wl1251 *wl)
K
Kalle Valo 已提交
32 33 34 35
{
	enable_irq(wl->irq);
}

36
void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
K
Kalle Valo 已提交
37
{
38 39
	wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
	wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
K
Kalle Valo 已提交
40 41
}

42
int wl1251_boot_soft_reset(struct wl1251 *wl)
K
Kalle Valo 已提交
43 44 45 46 47
{
	unsigned long timeout;
	u32 boot_data;

	/* perform soft reset */
48
	wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
K
Kalle Valo 已提交
49 50 51 52

	/* SOFT_RESET is self clearing */
	timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
	while (1) {
53 54
		boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
		wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
K
Kalle Valo 已提交
55 56 57 58 59 60
		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 */
61
			wl1251_error("soft reset timeout");
K
Kalle Valo 已提交
62 63 64 65 66 67 68
			return -1;
		}

		udelay(SOFT_RESET_STALL_TIME);
	}

	/* disable Rx/Tx */
69
	wl1251_reg_write32(wl, ENABLE, 0x0);
K
Kalle Valo 已提交
70 71

	/* disable auto calibration on start*/
72
	wl1251_reg_write32(wl, SPARE_A2, 0xffff);
K
Kalle Valo 已提交
73 74 75 76

	return 0;
}

77
int wl1251_boot_init_seq(struct wl1251 *wl)
K
Kalle Valo 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
{
	u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;

	/*
	 * col #1: INTEGER_DIVIDER
	 * col #2: FRACTIONAL_DIVIDER
	 * col #3: ATTN_BB
	 * col #4: ALPHA_BB
	 * col #5: STOP_TIME_BB
	 * col #6: BB_PLL_LOOP_FILTER
	 */
	static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {

		{   83, 87381,  0xB, 5, 0xF00,  3}, /* REF_FREQ_19_2*/
		{   61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
		{   41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
		{   40, 0,      0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
		{   47, 162280, 0xC, 6, 0x2760, 1}  /* REF_FREQ_33_6        */
	};

	/* read NVS params */
99 100
	scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
	wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
K
Kalle Valo 已提交
101 102

	/* read ELP_CMD */
103 104
	elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
	wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
K
Kalle Valo 已提交
105 106 107

	/* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
	ref_freq = scr_pad6 & 0x000000FF;
108
	wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
K
Kalle Valo 已提交
109

110
	wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
K
Kalle Valo 已提交
111 112 113 114

	/*
	 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
	 */
115
	wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
K
Kalle Valo 已提交
116 117 118 119 120 121 122

	/*
	 * set the clock detect feature to work in the restart wu procedure
	 * (ELP_CFG_MODE[14]) and Select the clock source type
	 * (ELP_CFG_MODE[13:12])
	 */
	tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
123
	wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
K
Kalle Valo 已提交
124 125 126

	/* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
	elp_cmd |= 0x00000040;
127
	wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
K
Kalle Valo 已提交
128 129 130

	/* PG 1.2: Set the BB PLL stable time to be 1000usec
	 * (PLL_STABLE_TIME) */
131
	wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
K
Kalle Valo 已提交
132 133

	/* PG 1.2: read clock request time */
134
	init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
K
Kalle Valo 已提交
135 136 137 138 139 140 141 142 143

	/*
	 * PG 1.2: set the clock request time to be ref_clk_settling_time -
	 * 1ms = 4ms
	 */
	if (init_data > 0x21)
		tmp = init_data - 0x21;
	else
		tmp = 0;
144
	wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
K
Kalle Valo 已提交
145 146

	/* set BB PLL configurations in RF AFE */
147
	wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
K
Kalle Valo 已提交
148 149

	/* set RF_AFE_REG_5 */
150
	wl1251_reg_write32(wl, 0x003058d4, 0x50);
K
Kalle Valo 已提交
151 152

	/* set RF_AFE_CTRL_REG_2 */
153
	wl1251_reg_write32(wl, 0x00305948, 0x11c001);
K
Kalle Valo 已提交
154 155 156 157 158

	/*
	 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
	 * bais current(RF_AFE_REG_13)
	 */
159
	wl1251_reg_write32(wl, 0x003058f4, 0x1e);
K
Kalle Valo 已提交
160 161 162

	/* set BB PLL configurations */
	tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
163
	wl1251_reg_write32(wl, 0x00305840, tmp);
K
Kalle Valo 已提交
164 165 166 167 168

	/* set fractional divider according to Appendix C-BB PLL
	 * Calculations
	 */
	tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
169
	wl1251_reg_write32(wl, 0x00305844, tmp);
K
Kalle Valo 已提交
170 171

	/* set the initial data for the sigma delta */
172
	wl1251_reg_write32(wl, 0x00305848, 0x3039);
K
Kalle Valo 已提交
173 174 175 176 177 178 179 180

	/*
	 * set the accumulator attenuation value, calibration loop1
	 * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
	 * the VCO gain
	 */
	tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
		(LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
181
	wl1251_reg_write32(wl, 0x00305854, tmp);
K
Kalle Valo 已提交
182 183 184 185 186 187

	/*
	 * set the calibration stop time after holdoff time expires and set
	 * settling time HOLD_OFF_TIME_BB
	 */
	tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
188
	wl1251_reg_write32(wl, 0x00305858, tmp);
K
Kalle Valo 已提交
189 190 191 192 193 194 195

	/*
	 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
	 * constant leakage current to linearize PFD to 0uA -
	 * BB_ILOOPF[7:3]
	 */
	tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
196
	wl1251_reg_write32(wl, 0x003058f8, tmp);
K
Kalle Valo 已提交
197 198 199 200 201 202 203

	/*
	 * set regulator output voltage for n divider to
	 * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
	 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
	 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
	 */
204
	wl1251_reg_write32(wl, 0x003058f0, 0x29);
K
Kalle Valo 已提交
205 206

	/* enable restart wakeup sequence (ELP_CMD[0]) */
207
	wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
K
Kalle Valo 已提交
208 209 210 211 212 213 214

	/* restart sequence completed */
	udelay(2000);

	return 0;
}

215
int wl1251_boot_run_firmware(struct wl1251 *wl)
K
Kalle Valo 已提交
216 217 218 219 220 221
{
	int loop, ret;
	u32 chip_id, interrupt;

	wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);

222
	chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
K
Kalle Valo 已提交
223

224
	wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
K
Kalle Valo 已提交
225 226

	if (chip_id != wl->chip.id) {
227
		wl1251_error("chip id doesn't match after firmware boot");
K
Kalle Valo 已提交
228 229 230 231 232 233 234
		return -EIO;
	}

	/* wait for init to complete */
	loop = 0;
	while (loop++ < INIT_LOOP) {
		udelay(INIT_LOOP_DELAY);
235
		interrupt = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
K
Kalle Valo 已提交
236 237

		if (interrupt == 0xffffffff) {
238
			wl1251_error("error reading hardware complete "
K
Kalle Valo 已提交
239 240 241 242 243
				     "init indication");
			return -EIO;
		}
		/* check that ACX_INTR_INIT_COMPLETE is enabled */
		else if (interrupt & wl->chip.intr_init_complete) {
244
			wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
K
Kalle Valo 已提交
245 246 247 248 249 250
					   wl->chip.intr_init_complete);
			break;
		}
	}

	if (loop >= INIT_LOOP) {
251
		wl1251_error("timeout waiting for the hardware to "
K
Kalle Valo 已提交
252 253 254 255 256
			     "complete initialization");
		return -EIO;
	}

	/* get hardware config command mail box */
257
	wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
K
Kalle Valo 已提交
258 259

	/* get hardware config event mail box */
260
	wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
K
Kalle Valo 已提交
261 262

	/* set the working partition to its "running" mode offset */
263
	wl1251_set_partition(wl,
K
Kalle Valo 已提交
264 265 266 267 268
			     wl->chip.p_table[PART_WORK].mem.start,
			     wl->chip.p_table[PART_WORK].mem.size,
			     wl->chip.p_table[PART_WORK].reg.start,
			     wl->chip.p_table[PART_WORK].reg.size);

269
	wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
K
Kalle Valo 已提交
270 271
		     wl->cmd_box_addr, wl->event_box_addr);

272 273
	wl->chip.op_fw_version(wl);

K
Kalle Valo 已提交
274 275 276 277 278 279
	/*
	 * in case of full asynchronous mode the firmware event must be
	 * ready to receive event from the command mailbox
	 */

	/* enable gpio interrupts */
280
	wl1251_boot_enable_interrupts(wl);
K
Kalle Valo 已提交
281 282 283 284 285 286

	wl->chip.op_target_enable_interrupts(wl);

	/* unmask all mbox events  */
	wl->event_mask = 0xffffffff;

287
	ret = wl1251_event_unmask(wl);
K
Kalle Valo 已提交
288
	if (ret < 0) {
289
		wl1251_error("EVENT mask setting failed");
K
Kalle Valo 已提交
290 291 292
		return ret;
	}

293
	wl1251_event_mbox_config(wl);
K
Kalle Valo 已提交
294 295 296 297

	/* firmware startup completed */
	return 0;
}