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> |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 25 | #include <linux/wl12xx.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 27 | #include "acx.h" |
| 28 | #include "reg.h" |
| 29 | #include "boot.h" |
| 30 | #include "io.h" |
| 31 | #include "event.h" |
Arik Nemtsov | ae113b5 | 2010-10-16 18:45:07 +0200 | [diff] [blame] | 32 | #include "rx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 33 | |
| 34 | static struct wl1271_partition_set part_table[PART_TABLE_LEN] = { |
| 35 | [PART_DOWN] = { |
| 36 | .mem = { |
| 37 | .start = 0x00000000, |
| 38 | .size = 0x000177c0 |
| 39 | }, |
| 40 | .reg = { |
| 41 | .start = REGISTERS_BASE, |
| 42 | .size = 0x00008800 |
| 43 | }, |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 44 | .mem2 = { |
| 45 | .start = 0x00000000, |
| 46 | .size = 0x00000000 |
| 47 | }, |
| 48 | .mem3 = { |
| 49 | .start = 0x00000000, |
| 50 | .size = 0x00000000 |
| 51 | }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 52 | }, |
| 53 | |
| 54 | [PART_WORK] = { |
| 55 | .mem = { |
| 56 | .start = 0x00040000, |
| 57 | .size = 0x00014fc0 |
| 58 | }, |
| 59 | .reg = { |
| 60 | .start = REGISTERS_BASE, |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 61 | .size = 0x0000a000 |
| 62 | }, |
| 63 | .mem2 = { |
| 64 | .start = 0x003004f8, |
| 65 | .size = 0x00000004 |
| 66 | }, |
| 67 | .mem3 = { |
| 68 | .start = 0x00040404, |
| 69 | .size = 0x00000000 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 70 | }, |
| 71 | }, |
| 72 | |
| 73 | [PART_DRPW] = { |
| 74 | .mem = { |
| 75 | .start = 0x00040000, |
| 76 | .size = 0x00014fc0 |
| 77 | }, |
| 78 | .reg = { |
| 79 | .start = DRPW_BASE, |
| 80 | .size = 0x00006000 |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 81 | }, |
| 82 | .mem2 = { |
| 83 | .start = 0x00000000, |
| 84 | .size = 0x00000000 |
| 85 | }, |
| 86 | .mem3 = { |
| 87 | .start = 0x00000000, |
| 88 | .size = 0x00000000 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag) |
| 94 | { |
| 95 | u32 cpu_ctrl; |
| 96 | |
| 97 | /* 10.5.0 run the firmware (I) */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 98 | cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 99 | |
| 100 | /* 10.5.1 run the firmware (II) */ |
| 101 | cpu_ctrl |= flag; |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 102 | wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 103 | } |
| 104 | |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 105 | static void wl1271_parse_fw_ver(struct wl1271 *wl) |
| 106 | { |
| 107 | int ret; |
| 108 | |
| 109 | ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u", |
| 110 | &wl->chip.fw_ver[0], &wl->chip.fw_ver[1], |
| 111 | &wl->chip.fw_ver[2], &wl->chip.fw_ver[3], |
| 112 | &wl->chip.fw_ver[4]); |
| 113 | |
| 114 | if (ret != 5) { |
| 115 | wl1271_warning("fw version incorrect value"); |
| 116 | memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver)); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 121 | static void wl1271_boot_fw_version(struct wl1271 *wl) |
| 122 | { |
| 123 | struct wl1271_static_data static_data; |
| 124 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 125 | wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data), |
| 126 | false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 127 | |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 128 | strncpy(wl->chip.fw_ver_str, static_data.fw_version, |
| 129 | sizeof(wl->chip.fw_ver_str)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 130 | |
| 131 | /* make sure the string is NULL-terminated */ |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 132 | wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0'; |
| 133 | |
| 134 | wl1271_parse_fw_ver(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, |
| 138 | size_t fw_data_len, u32 dest) |
| 139 | { |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 140 | struct wl1271_partition_set partition; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 141 | int addr, chunk_num, partition_limit; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 142 | u8 *p, *chunk; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 143 | |
| 144 | /* whal_FwCtrl_LoadFwImageSm() */ |
| 145 | |
| 146 | wl1271_debug(DEBUG_BOOT, "starting firmware upload"); |
| 147 | |
Luciano Coelho | 73d0a13 | 2009-08-11 11:58:27 +0300 | [diff] [blame] | 148 | wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d", |
| 149 | fw_data_len, CHUNK_SIZE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 150 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 151 | if ((fw_data_len % 4) != 0) { |
| 152 | wl1271_error("firmware length not multiple of four"); |
| 153 | return -EIO; |
| 154 | } |
| 155 | |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 156 | chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL); |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 157 | if (!chunk) { |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 158 | wl1271_error("allocation for firmware upload chunk failed"); |
| 159 | return -ENOMEM; |
| 160 | } |
| 161 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 162 | memcpy(&partition, &part_table[PART_DOWN], sizeof(partition)); |
| 163 | partition.mem.start = dest; |
| 164 | wl1271_set_partition(wl, &partition); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 165 | |
| 166 | /* 10.1 set partition limit and chunk num */ |
| 167 | chunk_num = 0; |
| 168 | partition_limit = part_table[PART_DOWN].mem.size; |
| 169 | |
| 170 | while (chunk_num < fw_data_len / CHUNK_SIZE) { |
| 171 | /* 10.2 update partition, if needed */ |
| 172 | addr = dest + (chunk_num + 2) * CHUNK_SIZE; |
| 173 | if (addr > partition_limit) { |
| 174 | addr = dest + chunk_num * CHUNK_SIZE; |
| 175 | partition_limit = chunk_num * CHUNK_SIZE + |
| 176 | part_table[PART_DOWN].mem.size; |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 177 | partition.mem.start = addr; |
| 178 | wl1271_set_partition(wl, &partition); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* 10.3 upload the chunk */ |
| 182 | addr = dest + chunk_num * CHUNK_SIZE; |
| 183 | p = buf + chunk_num * CHUNK_SIZE; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 184 | memcpy(chunk, p, CHUNK_SIZE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 185 | wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", |
| 186 | p, addr); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 187 | wl1271_write(wl, addr, chunk, CHUNK_SIZE, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 188 | |
| 189 | chunk_num++; |
| 190 | } |
| 191 | |
| 192 | /* 10.4 upload the last chunk */ |
| 193 | addr = dest + chunk_num * CHUNK_SIZE; |
| 194 | p = buf + chunk_num * CHUNK_SIZE; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 195 | memcpy(chunk, p, fw_data_len % CHUNK_SIZE); |
Luciano Coelho | 73d0a13 | 2009-08-11 11:58:27 +0300 | [diff] [blame] | 196 | 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] | 197 | fw_data_len % CHUNK_SIZE, p, addr); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 198 | wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 199 | |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 200 | kfree(chunk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int wl1271_boot_upload_firmware(struct wl1271 *wl) |
| 205 | { |
| 206 | u32 chunks, addr, len; |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 207 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 208 | u8 *fw; |
| 209 | |
| 210 | fw = wl->fw; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 211 | chunks = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 212 | fw += sizeof(u32); |
| 213 | |
| 214 | wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks); |
| 215 | |
| 216 | while (chunks--) { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 217 | addr = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 218 | fw += sizeof(u32); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 219 | len = be32_to_cpup((__be32 *) fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 220 | fw += sizeof(u32); |
| 221 | |
| 222 | if (len > 300000) { |
| 223 | wl1271_info("firmware chunk too long: %u", len); |
| 224 | return -EINVAL; |
| 225 | } |
| 226 | wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u", |
| 227 | chunks, addr, len); |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 228 | ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr); |
| 229 | if (ret != 0) |
| 230 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 231 | fw += len; |
| 232 | } |
| 233 | |
Juuso Oikarinen | ed317788 | 2009-10-13 12:47:57 +0300 | [diff] [blame] | 234 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static int wl1271_boot_upload_nvs(struct wl1271 *wl) |
| 238 | { |
| 239 | size_t nvs_len, burst_len; |
| 240 | int i; |
| 241 | u32 dest_addr, val; |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 242 | u8 *nvs_ptr, *nvs_aligned; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 243 | |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 244 | if (wl->nvs == NULL) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 245 | return -ENODEV; |
| 246 | |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 247 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
| 248 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 249 | |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 250 | if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) { |
| 251 | if (nvs->general_params.dual_mode_select) |
| 252 | wl->enable_11a = true; |
| 253 | } else { |
| 254 | wl1271_error("nvs size is not as expected: %zu != %zu", |
| 255 | wl->nvs_len, |
| 256 | sizeof(struct wl128x_nvs_file)); |
| 257 | kfree(wl->nvs); |
| 258 | wl->nvs = NULL; |
| 259 | wl->nvs_len = 0; |
| 260 | return -EILSEQ; |
| 261 | } |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 262 | |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 263 | /* only the first part of the NVS needs to be uploaded */ |
| 264 | nvs_len = sizeof(nvs->nvs); |
| 265 | nvs_ptr = (u8 *)nvs->nvs; |
| 266 | |
| 267 | } else { |
| 268 | struct wl1271_nvs_file *nvs = |
| 269 | (struct wl1271_nvs_file *)wl->nvs; |
| 270 | /* |
| 271 | * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz |
| 272 | * band configurations) can be removed when those NVS files stop |
| 273 | * floating around. |
| 274 | */ |
| 275 | if (wl->nvs_len == sizeof(struct wl1271_nvs_file) || |
| 276 | wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) { |
| 277 | /* for now 11a is unsupported in AP mode */ |
| 278 | if (wl->bss_type != BSS_TYPE_AP_BSS && |
| 279 | nvs->general_params.dual_mode_select) |
| 280 | wl->enable_11a = true; |
| 281 | } |
| 282 | |
| 283 | if (wl->nvs_len != sizeof(struct wl1271_nvs_file) && |
| 284 | (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE || |
| 285 | wl->enable_11a)) { |
| 286 | wl1271_error("nvs size is not as expected: %zu != %zu", |
| 287 | wl->nvs_len, sizeof(struct wl1271_nvs_file)); |
| 288 | kfree(wl->nvs); |
| 289 | wl->nvs = NULL; |
| 290 | wl->nvs_len = 0; |
| 291 | return -EILSEQ; |
| 292 | } |
| 293 | |
| 294 | /* only the first part of the NVS needs to be uploaded */ |
| 295 | nvs_len = sizeof(nvs->nvs); |
| 296 | nvs_ptr = (u8 *) nvs->nvs; |
| 297 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 298 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 299 | /* update current MAC address to NVS */ |
| 300 | nvs_ptr[11] = wl->mac_addr[0]; |
| 301 | nvs_ptr[10] = wl->mac_addr[1]; |
| 302 | nvs_ptr[6] = wl->mac_addr[2]; |
| 303 | nvs_ptr[5] = wl->mac_addr[3]; |
| 304 | nvs_ptr[4] = wl->mac_addr[4]; |
| 305 | nvs_ptr[3] = wl->mac_addr[5]; |
| 306 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 307 | /* |
| 308 | * Layout before the actual NVS tables: |
| 309 | * 1 byte : burst length. |
| 310 | * 2 bytes: destination address. |
| 311 | * n bytes: data to burst copy. |
| 312 | * |
| 313 | * This is ended by a 0 length, then the NVS tables. |
| 314 | */ |
| 315 | |
| 316 | /* FIXME: Do we need to check here whether the LSB is 1? */ |
| 317 | while (nvs_ptr[0]) { |
| 318 | burst_len = nvs_ptr[0]; |
| 319 | dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8)); |
| 320 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 321 | /* |
| 322 | * Due to our new wl1271_translate_reg_addr function, |
| 323 | * we need to add the REGISTER_BASE to the destination |
| 324 | */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 325 | dest_addr += REGISTERS_BASE; |
| 326 | |
| 327 | /* We move our pointer to the data */ |
| 328 | nvs_ptr += 3; |
| 329 | |
| 330 | for (i = 0; i < burst_len; i++) { |
| 331 | val = (nvs_ptr[0] | (nvs_ptr[1] << 8) |
| 332 | | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); |
| 333 | |
| 334 | wl1271_debug(DEBUG_BOOT, |
| 335 | "nvs burst write 0x%x: 0x%x", |
| 336 | dest_addr, val); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 337 | wl1271_write32(wl, dest_addr, val); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 338 | |
| 339 | nvs_ptr += 4; |
| 340 | dest_addr += 4; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * We've reached the first zero length, the first NVS table |
Ido Yariv | 67e0208 | 2010-09-22 09:53:13 +0200 | [diff] [blame] | 346 | * is located at an aligned offset which is at least 7 bytes further. |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 347 | * NOTE: The wl->nvs->nvs element must be first, in order to |
| 348 | * simplify the casting, we assume it is at the beginning of |
| 349 | * the wl->nvs structure. |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 350 | */ |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 351 | nvs_ptr = (u8 *)wl->nvs + |
| 352 | ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4); |
| 353 | nvs_len -= nvs_ptr - (u8 *)wl->nvs; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 354 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 355 | /* Now we must set the partition correctly */ |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 356 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 357 | |
| 358 | /* Copy the NVS tables to a new block to ensure alignment */ |
Ido Yariv | 67e0208 | 2010-09-22 09:53:13 +0200 | [diff] [blame] | 359 | nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); |
| 360 | if (!nvs_aligned) |
| 361 | return -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 362 | |
| 363 | /* And finally we upload the NVS tables */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 364 | wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 365 | |
| 366 | kfree(nvs_aligned); |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static void wl1271_boot_enable_interrupts(struct wl1271 *wl) |
| 371 | { |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 372 | wl1271_enable_interrupts(wl); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 373 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, |
| 374 | WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); |
| 375 | wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static int wl1271_boot_soft_reset(struct wl1271 *wl) |
| 379 | { |
| 380 | unsigned long timeout; |
| 381 | u32 boot_data; |
| 382 | |
| 383 | /* perform soft reset */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 384 | 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] | 385 | |
| 386 | /* SOFT_RESET is self clearing */ |
| 387 | timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); |
| 388 | while (1) { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 389 | boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 390 | wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); |
| 391 | if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) |
| 392 | break; |
| 393 | |
| 394 | if (time_after(jiffies, timeout)) { |
| 395 | /* 1.2 check pWhalBus->uSelfClearTime if the |
| 396 | * timeout was reached */ |
| 397 | wl1271_error("soft reset timeout"); |
| 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | udelay(SOFT_RESET_STALL_TIME); |
| 402 | } |
| 403 | |
| 404 | /* disable Rx/Tx */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 405 | wl1271_write32(wl, ENABLE, 0x0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 406 | |
| 407 | /* disable auto calibration on start*/ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 408 | wl1271_write32(wl, SPARE_A2, 0xffff); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static int wl1271_boot_run_firmware(struct wl1271 *wl) |
| 414 | { |
| 415 | int loop, ret; |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 416 | u32 chip_id, intr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 417 | |
| 418 | wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT); |
| 419 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 420 | chip_id = wl1271_read32(wl, CHIP_ID_B); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 421 | |
| 422 | wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id); |
| 423 | |
| 424 | if (chip_id != wl->chip.id) { |
| 425 | wl1271_error("chip id doesn't match after firmware boot"); |
| 426 | return -EIO; |
| 427 | } |
| 428 | |
| 429 | /* wait for init to complete */ |
| 430 | loop = 0; |
| 431 | while (loop++ < INIT_LOOP) { |
| 432 | udelay(INIT_LOOP_DELAY); |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 433 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 434 | |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 435 | if (intr == 0xffffffff) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 436 | wl1271_error("error reading hardware complete " |
| 437 | "init indication"); |
| 438 | return -EIO; |
| 439 | } |
| 440 | /* check that ACX_INTR_INIT_COMPLETE is enabled */ |
Luciano Coelho | 23a7a51 | 2010-04-28 09:50:02 +0300 | [diff] [blame] | 441 | else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 442 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 443 | WL1271_ACX_INTR_INIT_COMPLETE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
Luciano Coelho | e7d17cf | 2009-10-29 13:20:04 +0200 | [diff] [blame] | 448 | if (loop > INIT_LOOP) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 449 | wl1271_error("timeout waiting for the hardware to " |
| 450 | "complete initialization"); |
| 451 | return -EIO; |
| 452 | } |
| 453 | |
| 454 | /* get hardware config command mail box */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 455 | wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 456 | |
| 457 | /* get hardware config event mail box */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 458 | wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 459 | |
| 460 | /* set the working partition to its "running" mode offset */ |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 461 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 462 | |
| 463 | wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x", |
| 464 | wl->cmd_box_addr, wl->event_box_addr); |
| 465 | |
| 466 | wl1271_boot_fw_version(wl); |
| 467 | |
| 468 | /* |
| 469 | * in case of full asynchronous mode the firmware event must be |
| 470 | * ready to receive event from the command mailbox |
| 471 | */ |
| 472 | |
Juuso Oikarinen | be823e5 | 2009-10-08 21:56:36 +0300 | [diff] [blame] | 473 | /* unmask required mbox events */ |
| 474 | wl->event_mask = BSS_LOSE_EVENT_ID | |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 475 | SCAN_COMPLETE_EVENT_ID | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 476 | PS_REPORT_EVENT_ID | |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 477 | JOIN_EVENT_COMPLETE_ID | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 478 | DISCONNECT_EVENT_COMPLETE_ID | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 479 | RSSI_SNR_TRIGGER_0_EVENT_ID | |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 480 | PSPOLL_DELIVERY_FAILURE_EVENT_ID | |
| 481 | SOFT_GEMINI_SENSE_EVENT_ID; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 482 | |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 483 | if (wl->bss_type == BSS_TYPE_AP_BSS) |
| 484 | wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 485 | else |
| 486 | wl->event_mask |= DUMMY_PACKET_EVENT_ID; |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 487 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 488 | ret = wl1271_event_unmask(wl); |
| 489 | if (ret < 0) { |
| 490 | wl1271_error("EVENT mask setting failed"); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | wl1271_event_mbox_config(wl); |
| 495 | |
| 496 | /* firmware startup completed */ |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int wl1271_boot_write_irq_polarity(struct wl1271 *wl) |
| 501 | { |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 502 | u32 polarity; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 503 | |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 504 | polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 505 | |
| 506 | /* We use HIGH polarity, so unset the LOW bit */ |
| 507 | polarity &= ~POLARITY_LOW; |
Juuso Oikarinen | e8768ee | 2009-10-12 15:08:48 +0300 | [diff] [blame] | 508 | wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 513 | static void wl1271_boot_hw_version(struct wl1271 *wl) |
| 514 | { |
| 515 | u32 fuse; |
| 516 | |
| 517 | fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1); |
| 518 | fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET; |
| 519 | |
| 520 | wl->hw_pg_ver = (s8)fuse; |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 521 | |
| 522 | if (((wl->hw_pg_ver & PG_MAJOR_VER_MASK) >> PG_MAJOR_VER_OFFSET) < 3) |
| 523 | wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 524 | } |
| 525 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 526 | static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl) |
| 527 | { |
| 528 | u16 spare_reg; |
| 529 | |
| 530 | /* Mask bits [2] & [8:4] in the sys_clk_cfg register */ |
| 531 | spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG); |
| 532 | if (spare_reg == 0xFFFF) |
| 533 | return -EFAULT; |
| 534 | spare_reg |= (BIT(3) | BIT(5) | BIT(6)); |
| 535 | wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg); |
| 536 | |
| 537 | /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */ |
| 538 | wl1271_top_reg_write(wl, SYS_CLK_CFG_REG, |
| 539 | WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF); |
| 540 | |
| 541 | /* Delay execution for 15msec, to let the HW settle */ |
| 542 | mdelay(15); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | static bool wl128x_is_tcxo_valid(struct wl1271 *wl) |
| 548 | { |
| 549 | u16 tcxo_detection; |
| 550 | |
| 551 | tcxo_detection = wl1271_top_reg_read(wl, TCXO_CLK_DETECT_REG); |
| 552 | if (tcxo_detection & TCXO_DET_FAILED) |
| 553 | return false; |
| 554 | |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | static bool wl128x_is_fref_valid(struct wl1271 *wl) |
| 559 | { |
| 560 | u16 fref_detection; |
| 561 | |
| 562 | fref_detection = wl1271_top_reg_read(wl, FREF_CLK_DETECT_REG); |
| 563 | if (fref_detection & FREF_CLK_DETECT_FAIL) |
| 564 | return false; |
| 565 | |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl) |
| 570 | { |
| 571 | wl1271_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL); |
| 572 | wl1271_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL); |
| 573 | wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL); |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk) |
| 579 | { |
| 580 | u16 spare_reg; |
| 581 | u16 pll_config; |
| 582 | u8 input_freq; |
| 583 | |
| 584 | /* Mask bits [3:1] in the sys_clk_cfg register */ |
| 585 | spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG); |
| 586 | if (spare_reg == 0xFFFF) |
| 587 | return -EFAULT; |
| 588 | spare_reg |= BIT(2); |
| 589 | wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg); |
| 590 | |
| 591 | /* Handle special cases of the TCXO clock */ |
| 592 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 || |
| 593 | wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6) |
| 594 | return wl128x_manually_configure_mcs_pll(wl); |
| 595 | |
| 596 | /* Set the input frequency according to the selected clock source */ |
| 597 | input_freq = (clk & 1) + 1; |
| 598 | |
| 599 | pll_config = wl1271_top_reg_read(wl, MCS_PLL_CONFIG_REG); |
| 600 | if (pll_config == 0xFFFF) |
| 601 | return -EFAULT; |
| 602 | pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT); |
| 603 | pll_config |= MCS_PLL_ENABLE_HP; |
| 604 | wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config); |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 609 | /* |
| 610 | * WL128x has two clocks input - TCXO and FREF. |
| 611 | * TCXO is the main clock of the device, while FREF is used to sync |
| 612 | * between the GPS and the cellular modem. |
| 613 | * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used |
| 614 | * as the WLAN/BT main clock. |
| 615 | */ |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 616 | static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 617 | { |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 618 | u16 sys_clk_cfg; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 619 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 620 | /* For XTAL-only modes, FREF will be used after switching from TCXO */ |
| 621 | if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL || |
| 622 | wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) { |
| 623 | if (!wl128x_switch_tcxo_to_fref(wl)) |
| 624 | return -EINVAL; |
| 625 | goto fref_clk; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 628 | /* Query the HW, to determine which clock source we should use */ |
| 629 | sys_clk_cfg = wl1271_top_reg_read(wl, SYS_CLK_CFG_REG); |
| 630 | if (sys_clk_cfg == 0xFFFF) |
| 631 | return -EINVAL; |
| 632 | if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF) |
| 633 | goto fref_clk; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 634 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 635 | /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */ |
| 636 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 || |
| 637 | wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) { |
| 638 | if (!wl128x_switch_tcxo_to_fref(wl)) |
| 639 | return -EINVAL; |
| 640 | goto fref_clk; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 643 | /* TCXO clock is selected */ |
| 644 | if (!wl128x_is_tcxo_valid(wl)) |
| 645 | return -EINVAL; |
| 646 | *selected_clock = wl->tcxo_clock; |
| 647 | goto config_mcs_pll; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 648 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 649 | fref_clk: |
| 650 | /* FREF clock is selected */ |
| 651 | if (!wl128x_is_fref_valid(wl)) |
| 652 | return -EINVAL; |
| 653 | *selected_clock = wl->ref_clock; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 654 | |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 655 | config_mcs_pll: |
| 656 | return wl128x_configure_mcs_pll(wl, *selected_clock); |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static int wl127x_boot_clk(struct wl1271 *wl) |
| 660 | { |
| 661 | u32 pause; |
| 662 | u32 clk; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 663 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 664 | wl1271_boot_hw_version(wl); |
| 665 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 666 | if (wl->ref_clock == CONF_REF_CLK_19_2_E || |
| 667 | wl->ref_clock == CONF_REF_CLK_38_4_E || |
| 668 | wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL) |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 669 | /* ref clk: 19.2/38.4/38.4-XTAL */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 670 | clk = 0x3; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 671 | else if (wl->ref_clock == CONF_REF_CLK_26_E || |
| 672 | wl->ref_clock == CONF_REF_CLK_52_E) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 673 | /* ref clk: 26/52 */ |
| 674 | clk = 0x5; |
Ohad Ben-Cohen | 15cea99 | 2010-09-16 01:31:51 +0200 | [diff] [blame] | 675 | else |
| 676 | return -EINVAL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 677 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 678 | if (wl->ref_clock != CONF_REF_CLK_19_2_E) { |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 679 | u16 val; |
Juuso Oikarinen | 9d4e5bb | 2010-03-26 12:53:15 +0200 | [diff] [blame] | 680 | /* Set clock type (open drain) */ |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 681 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE); |
| 682 | val &= FREF_CLK_TYPE_BITS; |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 683 | wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val); |
Juuso Oikarinen | 9d4e5bb | 2010-03-26 12:53:15 +0200 | [diff] [blame] | 684 | |
| 685 | /* Set clock pull mode (no pull) */ |
| 686 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL); |
| 687 | val |= NO_PULL; |
| 688 | wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val); |
Juuso Oikarinen | 284134e | 2009-10-12 15:08:49 +0300 | [diff] [blame] | 689 | } else { |
| 690 | u16 val; |
| 691 | /* Set clock polarity */ |
| 692 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY); |
| 693 | val &= FREF_CLK_POLARITY_BITS; |
| 694 | val |= CLK_REQ_OUTN_SEL; |
| 695 | wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val); |
| 696 | } |
| 697 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 698 | wl1271_write32(wl, PLL_PARAMETERS, clk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 699 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 700 | pause = wl1271_read32(wl, PLL_PARAMETERS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 701 | |
| 702 | wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); |
| 703 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 704 | pause &= ~(WU_COUNTER_PAUSE_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 705 | pause |= WU_COUNTER_PAUSE_VAL; |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 706 | wl1271_write32(wl, WU_COUNTER_PAUSE, pause); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 707 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | /* uploads NVS and firmware */ |
| 712 | int wl1271_load_firmware(struct wl1271 *wl) |
| 713 | { |
| 714 | int ret = 0; |
| 715 | u32 tmp, clk; |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 716 | int selected_clock = -1; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 717 | |
| 718 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 719 | ret = wl128x_boot_clk(wl, &selected_clock); |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 720 | if (ret < 0) |
| 721 | goto out; |
| 722 | } else { |
| 723 | ret = wl127x_boot_clk(wl); |
| 724 | if (ret < 0) |
| 725 | goto out; |
| 726 | } |
| 727 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 728 | /* Continue the ELP wake up sequence */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 729 | wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 730 | udelay(500); |
| 731 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 732 | wl1271_set_partition(wl, &part_table[PART_DRPW]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 733 | |
| 734 | /* Read-modify-write DRPW_SCRATCH_START register (see next state) |
| 735 | to be used by DRPw FW. The RTRIM value will be added by the FW |
| 736 | before taking DRPw out of reset */ |
| 737 | |
| 738 | wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 739 | clk = wl1271_read32(wl, DRPW_SCRATCH_START); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 740 | |
| 741 | wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); |
| 742 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 743 | if (wl->chip.id == CHIP_ID_1283_PG20) { |
Ido Yariv | d29633b | 2011-03-31 10:06:57 +0200 | [diff] [blame] | 744 | clk |= ((selected_clock & 0x3) << 1) << 4; |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 745 | } else { |
| 746 | clk |= (wl->ref_clock << 1) << 4; |
| 747 | } |
| 748 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 749 | wl1271_write32(wl, DRPW_SCRATCH_START, clk); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 750 | |
Juuso Oikarinen | 451de97 | 2009-10-12 15:08:46 +0300 | [diff] [blame] | 751 | wl1271_set_partition(wl, &part_table[PART_WORK]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 752 | |
| 753 | /* Disable interrupts */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 754 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 755 | |
| 756 | ret = wl1271_boot_soft_reset(wl); |
| 757 | if (ret < 0) |
| 758 | goto out; |
| 759 | |
| 760 | /* 2. start processing NVS file */ |
| 761 | ret = wl1271_boot_upload_nvs(wl); |
| 762 | if (ret < 0) |
| 763 | goto out; |
| 764 | |
| 765 | /* write firmware's last address (ie. it's length) to |
| 766 | * ACX_EEPROMLESS_IND_REG */ |
| 767 | wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG"); |
| 768 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 769 | wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 770 | |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 771 | tmp = wl1271_read32(wl, CHIP_ID_B); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 772 | |
| 773 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp); |
| 774 | |
| 775 | /* 6. read the EEPROM parameters */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 776 | tmp = wl1271_read32(wl, SCR_PAD2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 777 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 778 | /* WL1271: The reference driver skips steps 7 to 10 (jumps directly |
| 779 | * to upload_fw) */ |
| 780 | |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 781 | if (wl->chip.id == CHIP_ID_1283_PG20) |
Luciano Coelho | afb7d3c | 2011-04-01 20:48:02 +0300 | [diff] [blame^] | 782 | wl1271_top_reg_write(wl, SDIO_IO_DS, wl->conf.hci_io_ds); |
Shahar Levi | 5ea417a | 2011-03-06 16:32:11 +0200 | [diff] [blame] | 783 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 784 | ret = wl1271_boot_upload_firmware(wl); |
| 785 | if (ret < 0) |
| 786 | goto out; |
| 787 | |
Roger Quadros | 870c367 | 2010-11-29 16:24:57 +0200 | [diff] [blame] | 788 | out: |
| 789 | return ret; |
| 790 | } |
| 791 | EXPORT_SYMBOL_GPL(wl1271_load_firmware); |
| 792 | |
| 793 | int wl1271_boot(struct wl1271 *wl) |
| 794 | { |
| 795 | int ret; |
| 796 | |
| 797 | /* upload NVS and firmware */ |
| 798 | ret = wl1271_load_firmware(wl); |
| 799 | if (ret) |
| 800 | return ret; |
| 801 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 802 | /* 10.5 start firmware */ |
| 803 | ret = wl1271_boot_run_firmware(wl); |
| 804 | if (ret < 0) |
| 805 | goto out; |
| 806 | |
Shahar Levi | b9b0fde | 2011-03-06 16:32:06 +0200 | [diff] [blame] | 807 | ret = wl1271_boot_write_irq_polarity(wl); |
| 808 | if (ret < 0) |
| 809 | goto out; |
| 810 | |
| 811 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, |
| 812 | WL1271_ACX_ALL_EVENTS_VECTOR); |
| 813 | |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 814 | /* Enable firmware interrupts now */ |
| 815 | wl1271_boot_enable_interrupts(wl); |
| 816 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 817 | /* set the wl1271 default filters */ |
Arik Nemtsov | ae113b5 | 2010-10-16 18:45:07 +0200 | [diff] [blame] | 818 | wl1271_set_default_filters(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 819 | |
| 820 | wl1271_event_mbox_config(wl); |
| 821 | |
| 822 | out: |
| 823 | return ret; |
| 824 | } |