blob: 5c6f32757ac421d67baef21f342440d9dcecf582 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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>
25
26#include "reg.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030027#include "wl1251_boot.h"
Bob Copeland0764de62009-08-07 13:32:56 +030028#include "wl1251_io.h"
Bob Copeland08d9f5722009-08-07 13:33:11 +030029#include "wl1251_spi.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030030#include "wl1251_event.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030031
Kalle Valo80301cd2009-06-12 14:17:39 +030032static void wl1251_boot_enable_interrupts(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030033{
34 enable_irq(wl->irq);
35}
36
Kalle Valo80301cd2009-06-12 14:17:39 +030037void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030038{
Kalle Valo80301cd2009-06-12 14:17:39 +030039 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
40 wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030041}
42
Kalle Valo80301cd2009-06-12 14:17:39 +030043int wl1251_boot_soft_reset(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030044{
45 unsigned long timeout;
46 u32 boot_data;
47
48 /* perform soft reset */
Kalle Valo80301cd2009-06-12 14:17:39 +030049 wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030050
51 /* SOFT_RESET is self clearing */
52 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
53 while (1) {
Kalle Valo80301cd2009-06-12 14:17:39 +030054 boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
55 wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030056 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
57 break;
58
59 if (time_after(jiffies, timeout)) {
60 /* 1.2 check pWhalBus->uSelfClearTime if the
61 * timeout was reached */
Kalle Valo80301cd2009-06-12 14:17:39 +030062 wl1251_error("soft reset timeout");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030063 return -1;
64 }
65
66 udelay(SOFT_RESET_STALL_TIME);
67 }
68
69 /* disable Rx/Tx */
Kalle Valo80301cd2009-06-12 14:17:39 +030070 wl1251_reg_write32(wl, ENABLE, 0x0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030071
72 /* disable auto calibration on start*/
Kalle Valo80301cd2009-06-12 14:17:39 +030073 wl1251_reg_write32(wl, SPARE_A2, 0xffff);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030074
75 return 0;
76}
77
Kalle Valo80301cd2009-06-12 14:17:39 +030078int wl1251_boot_init_seq(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030079{
80 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
81
82 /*
83 * col #1: INTEGER_DIVIDER
84 * col #2: FRACTIONAL_DIVIDER
85 * col #3: ATTN_BB
86 * col #4: ALPHA_BB
87 * col #5: STOP_TIME_BB
88 * col #6: BB_PLL_LOOP_FILTER
89 */
90 static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
91
92 { 83, 87381, 0xB, 5, 0xF00, 3}, /* REF_FREQ_19_2*/
93 { 61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
94 { 41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
95 { 40, 0, 0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
96 { 47, 162280, 0xC, 6, 0x2760, 1} /* REF_FREQ_33_6 */
97 };
98
99 /* read NVS params */
Kalle Valo80301cd2009-06-12 14:17:39 +0300100 scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
101 wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300102
103 /* read ELP_CMD */
Kalle Valo80301cd2009-06-12 14:17:39 +0300104 elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
105 wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300106
107 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
108 ref_freq = scr_pad6 & 0x000000FF;
Kalle Valo80301cd2009-06-12 14:17:39 +0300109 wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300110
Kalle Valo80301cd2009-06-12 14:17:39 +0300111 wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300112
113 /*
114 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
115 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300116 wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300117
118 /*
119 * set the clock detect feature to work in the restart wu procedure
120 * (ELP_CFG_MODE[14]) and Select the clock source type
121 * (ELP_CFG_MODE[13:12])
122 */
123 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
Kalle Valo80301cd2009-06-12 14:17:39 +0300124 wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300125
126 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
127 elp_cmd |= 0x00000040;
Kalle Valo80301cd2009-06-12 14:17:39 +0300128 wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300129
130 /* PG 1.2: Set the BB PLL stable time to be 1000usec
131 * (PLL_STABLE_TIME) */
Kalle Valo80301cd2009-06-12 14:17:39 +0300132 wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300133
134 /* PG 1.2: read clock request time */
Kalle Valo80301cd2009-06-12 14:17:39 +0300135 init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300136
137 /*
138 * PG 1.2: set the clock request time to be ref_clk_settling_time -
139 * 1ms = 4ms
140 */
141 if (init_data > 0x21)
142 tmp = init_data - 0x21;
143 else
144 tmp = 0;
Kalle Valo80301cd2009-06-12 14:17:39 +0300145 wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300146
147 /* set BB PLL configurations in RF AFE */
Kalle Valo80301cd2009-06-12 14:17:39 +0300148 wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300149
150 /* set RF_AFE_REG_5 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300151 wl1251_reg_write32(wl, 0x003058d4, 0x50);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300152
153 /* set RF_AFE_CTRL_REG_2 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300154 wl1251_reg_write32(wl, 0x00305948, 0x11c001);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300155
156 /*
157 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
158 * bais current(RF_AFE_REG_13)
159 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300160 wl1251_reg_write32(wl, 0x003058f4, 0x1e);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300161
162 /* set BB PLL configurations */
163 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
Kalle Valo80301cd2009-06-12 14:17:39 +0300164 wl1251_reg_write32(wl, 0x00305840, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300165
166 /* set fractional divider according to Appendix C-BB PLL
167 * Calculations
168 */
169 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
Kalle Valo80301cd2009-06-12 14:17:39 +0300170 wl1251_reg_write32(wl, 0x00305844, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300171
172 /* set the initial data for the sigma delta */
Kalle Valo80301cd2009-06-12 14:17:39 +0300173 wl1251_reg_write32(wl, 0x00305848, 0x3039);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300174
175 /*
176 * set the accumulator attenuation value, calibration loop1
177 * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
178 * the VCO gain
179 */
180 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
181 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
Kalle Valo80301cd2009-06-12 14:17:39 +0300182 wl1251_reg_write32(wl, 0x00305854, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300183
184 /*
185 * set the calibration stop time after holdoff time expires and set
186 * settling time HOLD_OFF_TIME_BB
187 */
188 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
Kalle Valo80301cd2009-06-12 14:17:39 +0300189 wl1251_reg_write32(wl, 0x00305858, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300190
191 /*
192 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
193 * constant leakage current to linearize PFD to 0uA -
194 * BB_ILOOPF[7:3]
195 */
196 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
Kalle Valo80301cd2009-06-12 14:17:39 +0300197 wl1251_reg_write32(wl, 0x003058f8, tmp);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300198
199 /*
200 * set regulator output voltage for n divider to
201 * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
202 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
203 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
204 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300205 wl1251_reg_write32(wl, 0x003058f0, 0x29);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300206
207 /* enable restart wakeup sequence (ELP_CMD[0]) */
Kalle Valo80301cd2009-06-12 14:17:39 +0300208 wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300209
210 /* restart sequence completed */
211 udelay(2000);
212
213 return 0;
214}
215
Kalle Valo80301cd2009-06-12 14:17:39 +0300216int wl1251_boot_run_firmware(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300217{
218 int loop, ret;
219 u32 chip_id, interrupt;
220
221 wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
222
Kalle Valo80301cd2009-06-12 14:17:39 +0300223 chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300224
Kalle Valo80301cd2009-06-12 14:17:39 +0300225 wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300226
227 if (chip_id != wl->chip.id) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300228 wl1251_error("chip id doesn't match after firmware boot");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300229 return -EIO;
230 }
231
232 /* wait for init to complete */
233 loop = 0;
234 while (loop++ < INIT_LOOP) {
235 udelay(INIT_LOOP_DELAY);
Kalle Valo80301cd2009-06-12 14:17:39 +0300236 interrupt = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300237
238 if (interrupt == 0xffffffff) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300239 wl1251_error("error reading hardware complete "
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300240 "init indication");
241 return -EIO;
242 }
243 /* check that ACX_INTR_INIT_COMPLETE is enabled */
244 else if (interrupt & wl->chip.intr_init_complete) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300245 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300246 wl->chip.intr_init_complete);
247 break;
248 }
249 }
250
251 if (loop >= INIT_LOOP) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300252 wl1251_error("timeout waiting for the hardware to "
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300253 "complete initialization");
254 return -EIO;
255 }
256
257 /* get hardware config command mail box */
Kalle Valo80301cd2009-06-12 14:17:39 +0300258 wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300259
260 /* get hardware config event mail box */
Kalle Valo80301cd2009-06-12 14:17:39 +0300261 wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300262
263 /* set the working partition to its "running" mode offset */
Kalle Valo80301cd2009-06-12 14:17:39 +0300264 wl1251_set_partition(wl,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300265 wl->chip.p_table[PART_WORK].mem.start,
266 wl->chip.p_table[PART_WORK].mem.size,
267 wl->chip.p_table[PART_WORK].reg.start,
268 wl->chip.p_table[PART_WORK].reg.size);
269
Kalle Valo80301cd2009-06-12 14:17:39 +0300270 wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300271 wl->cmd_box_addr, wl->event_box_addr);
272
Luciano Coelho0d1c3832009-06-12 14:15:27 +0300273 wl->chip.op_fw_version(wl);
274
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300275 /*
276 * in case of full asynchronous mode the firmware event must be
277 * ready to receive event from the command mailbox
278 */
279
280 /* enable gpio interrupts */
Kalle Valo80301cd2009-06-12 14:17:39 +0300281 wl1251_boot_enable_interrupts(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300282
283 wl->chip.op_target_enable_interrupts(wl);
284
285 /* unmask all mbox events */
286 wl->event_mask = 0xffffffff;
287
Kalle Valo80301cd2009-06-12 14:17:39 +0300288 ret = wl1251_event_unmask(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300289 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300290 wl1251_error("EVENT mask setting failed");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300291 return ret;
292 }
293
Kalle Valo80301cd2009-06-12 14:17:39 +0300294 wl1251_event_mbox_config(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300295
296 /* firmware startup completed */
297 return 0;
298}