Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 Nokia Corporation |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5 | * |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 25 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 26 | #include "acx.h" |
| 27 | #include "reg.h" |
| 28 | #include "boot.h" |
| 29 | #include "io.h" |
| 30 | #include "event.h" |
Arik Nemtsov | ae113b5 | 2010-10-16 18:45:07 +0200 | [diff] [blame] | 31 | #include "rx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 32 | |
| 33 | static 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 Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 43 | .mem2 = { |
| 44 | .start = 0x00000000, |
| 45 | .size = 0x00000000 |
| 46 | }, |
| 47 | .mem3 = { |
| 48 | .start = 0x00000000, |
| 49 | .size = 0x00000000 |
| 50 | }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 51 | }, |
| 52 | |
| 53 | [PART_WORK] = { |
| 54 | .mem = { |
| 55 | .start = 0x00040000, |
| 56 | .size = 0x00014fc0 |
| 57 | }, |
| 58 | .reg = { |
| 59 | .start = REGISTERS_BASE, |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 60 | .size = 0x0000a000 |
| 61 | }, |
| 62 | .mem2 = { |
| 63 | .start = 0x003004f8, |
| 64 | .size = 0x00000004 |
| 65 | }, |
| 66 | .mem3 = { |
| 67 | .start = 0x00040404, |
| 68 | .size = 0x00000000 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 69 | }, |
| 70 | }, |
| 71 | |
| 72 | [PART_DRPW] = { |
| 73 | .mem = { |
| 74 | .start = 0x00040000, |
| 75 | .size = 0x00014fc0 |
| 76 | }, |
| 77 | .reg = { |
| 78 | .start = DRPW_BASE, |
| 79 | .size = 0x00006000 |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 80 | }, |
| 81 | .mem2 = { |
| 82 | .start = 0x00000000, |
| 83 | .size = 0x00000000 |
| 84 | }, |
| 85 | .mem3 = { |
| 86 | .start = 0x00000000, |
| 87 | .size = 0x00000000 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | static 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 Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 97 | cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 98 | |
| 99 | /* 10.5.1 run the firmware (II) */ |
| 100 | cpu_ctrl |= flag; |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 101 | wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void wl1271_boot_fw_version(struct wl1271 *wl) |
| 105 | { |
| 106 | struct wl1271_static_data static_data; |
| 107 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 108 | wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data), |
| 109 | false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 110 | |
| 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 | |
| 118 | static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, |
| 119 | size_t fw_data_len, u32 dest) |
| 120 | { |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 121 | struct wl1271_partition_set partition; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 122 | int addr, chunk_num, partition_limit; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 123 | u8 *p, *chunk; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 124 | |
| 125 | /* whal_FwCtrl_LoadFwImageSm() */ |
| 126 | |
| 127 | wl1271_debug(DEBUG_BOOT, "starting firmware upload"); |
| 128 | |
Luciano Coelho | 73d0a13 | 2009-08-11 11:58:27 +0300 | [diff] [blame] | 129 | wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d", |
| 130 | fw_data_len, CHUNK_SIZE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 131 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 132 | if ((fw_data_len % 4) != 0) { |
| 133 | wl1271_error("firmware length not multiple of four"); |
| 134 | return -EIO; |
| 135 | } |
| 136 | |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 137 | chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL); |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 138 | if (!chunk) { |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 139 | wl1271_error("allocation for firmware upload chunk failed"); |
| 140 | return -ENOMEM; |
| 141 | } |
| 142 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 143 | memcpy(&partition, &part_table[PART_DOWN], sizeof(partition)); |
| 144 | partition.mem.start = dest; |
| 145 | wl1271_set_partition(wl, &partition); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 146 | |
| 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 Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 158 | partition.mem.start = addr; |
| 159 | wl1271_set_partition(wl, &partition); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /* 10.3 upload the chunk */ |
| 163 | addr = dest + chunk_num * CHUNK_SIZE; |
| 164 | p = buf + chunk_num * CHUNK_SIZE; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 165 | memcpy(chunk, p, CHUNK_SIZE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 166 | wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", |
| 167 | p, addr); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 168 | wl1271_write(wl, addr, chunk, CHUNK_SIZE, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 169 | |
| 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 Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 176 | memcpy(chunk, p, fw_data_len % CHUNK_SIZE); |
Luciano Coelho | 73d0a13 | 2009-08-11 11:58:27 +0300 | [diff] [blame] | 177 | wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x", |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 178 | fw_data_len % CHUNK_SIZE, p, addr); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 179 | wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 180 | |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 181 | kfree(chunk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int wl1271_boot_upload_firmware(struct wl1271 *wl) |
| 186 | { |
| 187 | u32 chunks, addr, len; |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 188 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 189 | u8 *fw; |
| 190 | |
| 191 | fw = wl->fw; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 192 | chunks = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 193 | fw += sizeof(u32); |
| 194 | |
| 195 | wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks); |
| 196 | |
| 197 | while (chunks--) { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 198 | addr = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 199 | fw += sizeof(u32); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 200 | len = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 201 | 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 Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 209 | ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr); |
| 210 | if (ret != 0) |
| 211 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 212 | fw += len; |
| 213 | } |
| 214 | |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 215 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static 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 Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 223 | u8 *nvs_ptr, *nvs_aligned; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 224 | |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 225 | if (wl->nvs == NULL) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 226 | return -ENODEV; |
| 227 | |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 228 | /* |
| 229 | * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz band |
| 230 | * configurations) can be removed when those NVS files stop floating |
| 231 | * around. |
| 232 | */ |
| 233 | if (wl->nvs_len == sizeof(struct wl1271_nvs_file) || |
| 234 | wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) { |
Arik Nemtsov | 038d925 | 2010-10-16 21:53:24 +0200 | [diff] [blame^] | 235 | /* for now 11a is unsupported in AP mode */ |
| 236 | if (wl->bss_type != BSS_TYPE_AP_BSS && |
| 237 | wl->nvs->general_params.dual_mode_select) |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 238 | wl->enable_11a = true; |
| 239 | } |
| 240 | |
| 241 | if (wl->nvs_len != sizeof(struct wl1271_nvs_file) && |
| 242 | (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE || |
| 243 | wl->enable_11a)) { |
| 244 | wl1271_error("nvs size is not as expected: %zu != %zu", |
| 245 | wl->nvs_len, sizeof(struct wl1271_nvs_file)); |
| 246 | kfree(wl->nvs); |
| 247 | wl->nvs = NULL; |
| 248 | wl->nvs_len = 0; |
| 249 | return -EILSEQ; |
| 250 | } |
| 251 | |
Luciano Coelho | 8cf5e8e | 2009-12-11 15:40:53 +0200 | [diff] [blame] | 252 | /* only the first part of the NVS needs to be uploaded */ |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 253 | nvs_len = sizeof(wl->nvs->nvs); |
| 254 | nvs_ptr = (u8 *)wl->nvs->nvs; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 255 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 256 | /* update current MAC address to NVS */ |
| 257 | nvs_ptr[11] = wl->mac_addr[0]; |
| 258 | nvs_ptr[10] = wl->mac_addr[1]; |
| 259 | nvs_ptr[6] = wl->mac_addr[2]; |
| 260 | nvs_ptr[5] = wl->mac_addr[3]; |
| 261 | nvs_ptr[4] = wl->mac_addr[4]; |
| 262 | nvs_ptr[3] = wl->mac_addr[5]; |
| 263 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 264 | /* |
| 265 | * Layout before the actual NVS tables: |
| 266 | * 1 byte : burst length. |
| 267 | * 2 bytes: destination address. |
| 268 | * n bytes: data to burst copy. |
| 269 | * |
| 270 | * This is ended by a 0 length, then the NVS tables. |
| 271 | */ |
| 272 | |
| 273 | /* FIXME: Do we need to check here whether the LSB is 1? */ |
| 274 | while (nvs_ptr[0]) { |
| 275 | burst_len = nvs_ptr[0]; |
| 276 | dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8)); |
| 277 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 278 | /* |
| 279 | * Due to our new wl1271_translate_reg_addr function, |
| 280 | * we need to add the REGISTER_BASE to the destination |
| 281 | */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 282 | dest_addr += REGISTERS_BASE; |
| 283 | |
| 284 | /* We move our pointer to the data */ |
| 285 | nvs_ptr += 3; |
| 286 | |
| 287 | for (i = 0; i < burst_len; i++) { |
| 288 | val = (nvs_ptr[0] | (nvs_ptr[1] << 8) |
| 289 | | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); |
| 290 | |
| 291 | wl1271_debug(DEBUG_BOOT, |
| 292 | "nvs burst write 0x%x: 0x%x", |
| 293 | dest_addr, val); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 294 | wl1271_write32(wl, dest_addr, val); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 295 | |
| 296 | nvs_ptr += 4; |
| 297 | dest_addr += 4; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * We've reached the first zero length, the first NVS table |
Ido Yariv | 67e0208 | 2010-09-22 09:53:13 +0200 | [diff] [blame] | 303 | * is located at an aligned offset which is at least 7 bytes further. |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 304 | */ |
Ido Yariv | 67e0208 | 2010-09-22 09:53:13 +0200 | [diff] [blame] | 305 | nvs_ptr = (u8 *)wl->nvs->nvs + |
| 306 | ALIGN(nvs_ptr - (u8 *)wl->nvs->nvs + 7, 4); |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 307 | nvs_len -= nvs_ptr - (u8 *)wl->nvs->nvs; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 308 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 309 | /* Now we must set the partition correctly */ |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 310 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 311 | |
| 312 | /* Copy the NVS tables to a new block to ensure alignment */ |
Ido Yariv | 67e0208 | 2010-09-22 09:53:13 +0200 | [diff] [blame] | 313 | nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); |
| 314 | if (!nvs_aligned) |
| 315 | return -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 316 | |
| 317 | /* And finally we upload the NVS tables */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 318 | wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 319 | |
| 320 | kfree(nvs_aligned); |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static void wl1271_boot_enable_interrupts(struct wl1271 *wl) |
| 325 | { |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 326 | wl1271_enable_interrupts(wl); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 327 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, |
| 328 | WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); |
| 329 | wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static int wl1271_boot_soft_reset(struct wl1271 *wl) |
| 333 | { |
| 334 | unsigned long timeout; |
| 335 | u32 boot_data; |
| 336 | |
| 337 | /* perform soft reset */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 338 | wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 339 | |
| 340 | /* SOFT_RESET is self clearing */ |
| 341 | timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); |
| 342 | while (1) { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 343 | boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 344 | wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); |
| 345 | if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) |
| 346 | break; |
| 347 | |
| 348 | if (time_after(jiffies, timeout)) { |
| 349 | /* 1.2 check pWhalBus->uSelfClearTime if the |
| 350 | * timeout was reached */ |
| 351 | wl1271_error("soft reset timeout"); |
| 352 | return -1; |
| 353 | } |
| 354 | |
| 355 | udelay(SOFT_RESET_STALL_TIME); |
| 356 | } |
| 357 | |
| 358 | /* disable Rx/Tx */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 359 | wl1271_write32(wl, ENABLE, 0x0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 360 | |
| 361 | /* disable auto calibration on start*/ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 362 | wl1271_write32(wl, SPARE_A2, 0xffff); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int wl1271_boot_run_firmware(struct wl1271 *wl) |
| 368 | { |
| 369 | int loop, ret; |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 370 | u32 chip_id, intr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 371 | |
| 372 | wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT); |
| 373 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 374 | chip_id = wl1271_read32(wl, CHIP_ID_B); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 375 | |
| 376 | wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id); |
| 377 | |
| 378 | if (chip_id != wl->chip.id) { |
| 379 | wl1271_error("chip id doesn't match after firmware boot"); |
| 380 | return -EIO; |
| 381 | } |
| 382 | |
| 383 | /* wait for init to complete */ |
| 384 | loop = 0; |
| 385 | while (loop++ < INIT_LOOP) { |
| 386 | udelay(INIT_LOOP_DELAY); |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 387 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 388 | |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 389 | if (intr == 0xffffffff) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 390 | wl1271_error("error reading hardware complete " |
| 391 | "init indication"); |
| 392 | return -EIO; |
| 393 | } |
| 394 | /* check that ACX_INTR_INIT_COMPLETE is enabled */ |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 395 | else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 396 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 397 | WL1271_ACX_INTR_INIT_COMPLETE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 398 | break; |
| 399 | } |
| 400 | } |
| 401 | |
Luciano Coelho | e7d17cf | 2009-10-29 13:20:04 +0200 | [diff] [blame] | 402 | if (loop > INIT_LOOP) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 403 | wl1271_error("timeout waiting for the hardware to " |
| 404 | "complete initialization"); |
| 405 | return -EIO; |
| 406 | } |
| 407 | |
| 408 | /* get hardware config command mail box */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 409 | wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 410 | |
| 411 | /* get hardware config event mail box */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 412 | wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 413 | |
| 414 | /* set the working partition to its "running" mode offset */ |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 415 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 416 | |
| 417 | wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x", |
| 418 | wl->cmd_box_addr, wl->event_box_addr); |
| 419 | |
| 420 | wl1271_boot_fw_version(wl); |
| 421 | |
| 422 | /* |
| 423 | * in case of full asynchronous mode the firmware event must be |
| 424 | * ready to receive event from the command mailbox |
| 425 | */ |
| 426 | |
Juuso Oikarinen | be823e5 | 2009-10-08 21:56:36 +0300 | [diff] [blame] | 427 | /* unmask required mbox events */ |
| 428 | wl->event_mask = BSS_LOSE_EVENT_ID | |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 429 | SCAN_COMPLETE_EVENT_ID | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 430 | PS_REPORT_EVENT_ID | |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 431 | JOIN_EVENT_COMPLETE_ID | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 432 | DISCONNECT_EVENT_COMPLETE_ID | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 433 | RSSI_SNR_TRIGGER_0_EVENT_ID | |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 434 | PSPOLL_DELIVERY_FAILURE_EVENT_ID | |
| 435 | SOFT_GEMINI_SENSE_EVENT_ID; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 436 | |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 437 | if (wl->bss_type == BSS_TYPE_AP_BSS) |
| 438 | wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID; |
| 439 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 440 | ret = wl1271_event_unmask(wl); |
| 441 | if (ret < 0) { |
| 442 | wl1271_error("EVENT mask setting failed"); |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | wl1271_event_mbox_config(wl); |
| 447 | |
| 448 | /* firmware startup completed */ |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int wl1271_boot_write_irq_polarity(struct wl1271 *wl) |
| 453 | { |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 454 | u32 polarity; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 455 | |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 456 | polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 457 | |
| 458 | /* We use HIGH polarity, so unset the LOW bit */ |
| 459 | polarity &= ~POLARITY_LOW; |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 460 | wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 465 | static void wl1271_boot_hw_version(struct wl1271 *wl) |
| 466 | { |
| 467 | u32 fuse; |
| 468 | |
| 469 | fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1); |
| 470 | fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET; |
| 471 | |
| 472 | wl->hw_pg_ver = (s8)fuse; |
| 473 | } |
| 474 | |
Roger Quadros | 870c367 | 2010-11-29 16:24:57 +0200 | [diff] [blame] | 475 | /* uploads NVS and firmware */ |
| 476 | int wl1271_load_firmware(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 477 | { |
| 478 | int ret = 0; |
| 479 | u32 tmp, clk, pause; |
| 480 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 481 | wl1271_boot_hw_version(wl); |
| 482 | |
Gery Kahn | c8aea56 | 2010-10-05 16:09:05 +0200 | [diff] [blame] | 483 | if (wl->ref_clock == 0 || wl->ref_clock == 2 || wl->ref_clock == 4) |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 484 | /* ref clk: 19.2/38.4/38.4-XTAL */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 485 | clk = 0x3; |
Gery Kahn | c8aea56 | 2010-10-05 16:09:05 +0200 | [diff] [blame] | 486 | else if (wl->ref_clock == 1 || wl->ref_clock == 3) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 487 | /* ref clk: 26/52 */ |
| 488 | clk = 0x5; |
Ohad Ben-Cohen | 15cea99 | 2010-09-16 01:31:51 +0200 | [diff] [blame] | 489 | else |
| 490 | return -EINVAL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 491 | |
Gery Kahn | c8aea56 | 2010-10-05 16:09:05 +0200 | [diff] [blame] | 492 | if (wl->ref_clock != 0) { |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 493 | u16 val; |
Juuso Oikarinen | 9d4e5bb | 2010-03-26 12:53:15 +0200 | [diff] [blame] | 494 | /* Set clock type (open drain) */ |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 495 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE); |
| 496 | val &= FREF_CLK_TYPE_BITS; |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 497 | wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val); |
Juuso Oikarinen | 9d4e5bb | 2010-03-26 12:53:15 +0200 | [diff] [blame] | 498 | |
| 499 | /* Set clock pull mode (no pull) */ |
| 500 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL); |
| 501 | val |= NO_PULL; |
| 502 | wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val); |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 503 | } else { |
| 504 | u16 val; |
| 505 | /* Set clock polarity */ |
| 506 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY); |
| 507 | val &= FREF_CLK_POLARITY_BITS; |
| 508 | val |= CLK_REQ_OUTN_SEL; |
| 509 | wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val); |
| 510 | } |
| 511 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 512 | wl1271_write32(wl, PLL_PARAMETERS, clk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 513 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 514 | pause = wl1271_read32(wl, PLL_PARAMETERS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 515 | |
| 516 | wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); |
| 517 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 518 | pause &= ~(WU_COUNTER_PAUSE_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 519 | pause |= WU_COUNTER_PAUSE_VAL; |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 520 | wl1271_write32(wl, WU_COUNTER_PAUSE, pause); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 521 | |
| 522 | /* Continue the ELP wake up sequence */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 523 | wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 524 | udelay(500); |
| 525 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 526 | wl1271_set_partition(wl, &part_table[PART_DRPW]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 527 | |
| 528 | /* Read-modify-write DRPW_SCRATCH_START register (see next state) |
| 529 | to be used by DRPw FW. The RTRIM value will be added by the FW |
| 530 | before taking DRPw out of reset */ |
| 531 | |
| 532 | wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 533 | clk = wl1271_read32(wl, DRPW_SCRATCH_START); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 534 | |
| 535 | wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); |
| 536 | |
Gery Kahn | c8aea56 | 2010-10-05 16:09:05 +0200 | [diff] [blame] | 537 | clk |= (wl->ref_clock << 1) << 4; |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 538 | wl1271_write32(wl, DRPW_SCRATCH_START, clk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 539 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 540 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 541 | |
| 542 | /* Disable interrupts */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 543 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 544 | |
| 545 | ret = wl1271_boot_soft_reset(wl); |
| 546 | if (ret < 0) |
| 547 | goto out; |
| 548 | |
| 549 | /* 2. start processing NVS file */ |
| 550 | ret = wl1271_boot_upload_nvs(wl); |
| 551 | if (ret < 0) |
| 552 | goto out; |
| 553 | |
| 554 | /* write firmware's last address (ie. it's length) to |
| 555 | * ACX_EEPROMLESS_IND_REG */ |
| 556 | wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG"); |
| 557 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 558 | wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 559 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 560 | tmp = wl1271_read32(wl, CHIP_ID_B); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 561 | |
| 562 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp); |
| 563 | |
| 564 | /* 6. read the EEPROM parameters */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 565 | tmp = wl1271_read32(wl, SCR_PAD2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 566 | |
| 567 | ret = wl1271_boot_write_irq_polarity(wl); |
| 568 | if (ret < 0) |
| 569 | goto out; |
| 570 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 571 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, |
| 572 | WL1271_ACX_ALL_EVENTS_VECTOR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 573 | |
| 574 | /* WL1271: The reference driver skips steps 7 to 10 (jumps directly |
| 575 | * to upload_fw) */ |
| 576 | |
| 577 | ret = wl1271_boot_upload_firmware(wl); |
| 578 | if (ret < 0) |
| 579 | goto out; |
| 580 | |
Roger Quadros | 870c367 | 2010-11-29 16:24:57 +0200 | [diff] [blame] | 581 | out: |
| 582 | return ret; |
| 583 | } |
| 584 | EXPORT_SYMBOL_GPL(wl1271_load_firmware); |
| 585 | |
| 586 | int wl1271_boot(struct wl1271 *wl) |
| 587 | { |
| 588 | int ret; |
| 589 | |
| 590 | /* upload NVS and firmware */ |
| 591 | ret = wl1271_load_firmware(wl); |
| 592 | if (ret) |
| 593 | return ret; |
| 594 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 595 | /* 10.5 start firmware */ |
| 596 | ret = wl1271_boot_run_firmware(wl); |
| 597 | if (ret < 0) |
| 598 | goto out; |
| 599 | |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 600 | /* Enable firmware interrupts now */ |
| 601 | wl1271_boot_enable_interrupts(wl); |
| 602 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 603 | /* set the wl1271 default filters */ |
Arik Nemtsov | ae113b5 | 2010-10-16 18:45:07 +0200 | [diff] [blame] | 604 | wl1271_set_default_filters(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 605 | |
| 606 | wl1271_event_mbox_config(wl); |
| 607 | |
| 608 | out: |
| 609 | return ret; |
| 610 | } |