boot.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2010 Nokia Corporation
  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. #include <linux/slab.h>
  24. #include <linux/wl12xx.h>
  25. #include "acx.h"
  26. #include "reg.h"
  27. #include "boot.h"
  28. #include "io.h"
  29. #include "event.h"
  30. #include "rx.h"
  31. static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
  32. [PART_DOWN] = {
  33. .mem = {
  34. .start = 0x00000000,
  35. .size = 0x000177c0
  36. },
  37. .reg = {
  38. .start = REGISTERS_BASE,
  39. .size = 0x00008800
  40. },
  41. .mem2 = {
  42. .start = 0x00000000,
  43. .size = 0x00000000
  44. },
  45. .mem3 = {
  46. .start = 0x00000000,
  47. .size = 0x00000000
  48. },
  49. },
  50. [PART_WORK] = {
  51. .mem = {
  52. .start = 0x00040000,
  53. .size = 0x00014fc0
  54. },
  55. .reg = {
  56. .start = REGISTERS_BASE,
  57. .size = 0x0000a000
  58. },
  59. .mem2 = {
  60. .start = 0x003004f8,
  61. .size = 0x00000004
  62. },
  63. .mem3 = {
  64. .start = 0x00040404,
  65. .size = 0x00000000
  66. },
  67. },
  68. [PART_DRPW] = {
  69. .mem = {
  70. .start = 0x00040000,
  71. .size = 0x00014fc0
  72. },
  73. .reg = {
  74. .start = DRPW_BASE,
  75. .size = 0x00006000
  76. },
  77. .mem2 = {
  78. .start = 0x00000000,
  79. .size = 0x00000000
  80. },
  81. .mem3 = {
  82. .start = 0x00000000,
  83. .size = 0x00000000
  84. }
  85. }
  86. };
  87. static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
  88. {
  89. u32 cpu_ctrl;
  90. /* 10.5.0 run the firmware (I) */
  91. cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL);
  92. /* 10.5.1 run the firmware (II) */
  93. cpu_ctrl |= flag;
  94. wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
  95. }
  96. static void wl1271_parse_fw_ver(struct wl1271 *wl)
  97. {
  98. int ret;
  99. ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
  100. &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
  101. &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
  102. &wl->chip.fw_ver[4]);
  103. if (ret != 5) {
  104. wl1271_warning("fw version incorrect value");
  105. memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
  106. return;
  107. }
  108. }
  109. static void wl1271_boot_fw_version(struct wl1271 *wl)
  110. {
  111. struct wl1271_static_data static_data;
  112. wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
  113. false);
  114. strncpy(wl->chip.fw_ver_str, static_data.fw_version,
  115. sizeof(wl->chip.fw_ver_str));
  116. /* make sure the string is NULL-terminated */
  117. wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
  118. wl1271_parse_fw_ver(wl);
  119. }
  120. static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
  121. size_t fw_data_len, u32 dest)
  122. {
  123. struct wl1271_partition_set partition;
  124. int addr, chunk_num, partition_limit;
  125. u8 *p, *chunk;
  126. /* whal_FwCtrl_LoadFwImageSm() */
  127. wl1271_debug(DEBUG_BOOT, "starting firmware upload");
  128. wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
  129. fw_data_len, CHUNK_SIZE);
  130. if ((fw_data_len % 4) != 0) {
  131. wl1271_error("firmware length not multiple of four");
  132. return -EIO;
  133. }
  134. chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
  135. if (!chunk) {
  136. wl1271_error("allocation for firmware upload chunk failed");
  137. return -ENOMEM;
  138. }
  139. memcpy(&partition, &part_table[PART_DOWN], sizeof(partition));
  140. partition.mem.start = dest;
  141. wl1271_set_partition(wl, &partition);
  142. /* 10.1 set partition limit and chunk num */
  143. chunk_num = 0;
  144. partition_limit = part_table[PART_DOWN].mem.size;
  145. while (chunk_num < fw_data_len / CHUNK_SIZE) {
  146. /* 10.2 update partition, if needed */
  147. addr = dest + (chunk_num + 2) * CHUNK_SIZE;
  148. if (addr > partition_limit) {
  149. addr = dest + chunk_num * CHUNK_SIZE;
  150. partition_limit = chunk_num * CHUNK_SIZE +
  151. part_table[PART_DOWN].mem.size;
  152. partition.mem.start = addr;
  153. wl1271_set_partition(wl, &partition);
  154. }
  155. /* 10.3 upload the chunk */
  156. addr = dest + chunk_num * CHUNK_SIZE;
  157. p = buf + chunk_num * CHUNK_SIZE;
  158. memcpy(chunk, p, CHUNK_SIZE);
  159. wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
  160. p, addr);
  161. wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
  162. chunk_num++;
  163. }
  164. /* 10.4 upload the last chunk */
  165. addr = dest + chunk_num * CHUNK_SIZE;
  166. p = buf + chunk_num * CHUNK_SIZE;
  167. memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
  168. wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
  169. fw_data_len % CHUNK_SIZE, p, addr);
  170. wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
  171. kfree(chunk);
  172. return 0;
  173. }
  174. static int wl1271_boot_upload_firmware(struct wl1271 *wl)
  175. {
  176. u32 chunks, addr, len;
  177. int ret = 0;
  178. u8 *fw;
  179. fw = wl->fw;
  180. chunks = be32_to_cpup((__be32 *) fw);
  181. fw += sizeof(u32);
  182. wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
  183. while (chunks--) {
  184. addr = be32_to_cpup((__be32 *) fw);
  185. fw += sizeof(u32);
  186. len = be32_to_cpup((__be32 *) fw);
  187. fw += sizeof(u32);
  188. if (len > 300000) {
  189. wl1271_info("firmware chunk too long: %u", len);
  190. return -EINVAL;
  191. }
  192. wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
  193. chunks, addr, len);
  194. ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
  195. if (ret != 0)
  196. break;
  197. fw += len;
  198. }
  199. return ret;
  200. }
  201. static int wl1271_boot_upload_nvs(struct wl1271 *wl)
  202. {
  203. size_t nvs_len, burst_len;
  204. int i;
  205. u32 dest_addr, val;
  206. u8 *nvs_ptr, *nvs_aligned;
  207. if (wl->nvs == NULL)
  208. return -ENODEV;
  209. if (wl->chip.id == CHIP_ID_1283_PG20) {
  210. struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
  211. if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
  212. if (nvs->general_params.dual_mode_select)
  213. wl->enable_11a = true;
  214. } else {
  215. wl1271_error("nvs size is not as expected: %zu != %zu",
  216. wl->nvs_len,
  217. sizeof(struct wl128x_nvs_file));
  218. kfree(wl->nvs);
  219. wl->nvs = NULL;
  220. wl->nvs_len = 0;
  221. return -EILSEQ;
  222. }
  223. /* only the first part of the NVS needs to be uploaded */
  224. nvs_len = sizeof(nvs->nvs);
  225. nvs_ptr = (u8 *)nvs->nvs;
  226. } else {
  227. struct wl1271_nvs_file *nvs =
  228. (struct wl1271_nvs_file *)wl->nvs;
  229. /*
  230. * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
  231. * band configurations) can be removed when those NVS files stop
  232. * floating around.
  233. */
  234. if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
  235. wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
  236. /* for now 11a is unsupported in AP mode */
  237. if (wl->bss_type != BSS_TYPE_AP_BSS &&
  238. nvs->general_params.dual_mode_select)
  239. wl->enable_11a = true;
  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. /* only the first part of the NVS needs to be uploaded */
  252. nvs_len = sizeof(nvs->nvs);
  253. nvs_ptr = (u8 *) nvs->nvs;
  254. }
  255. /* update current MAC address to NVS */
  256. nvs_ptr[11] = wl->mac_addr[0];
  257. nvs_ptr[10] = wl->mac_addr[1];
  258. nvs_ptr[6] = wl->mac_addr[2];
  259. nvs_ptr[5] = wl->mac_addr[3];
  260. nvs_ptr[4] = wl->mac_addr[4];
  261. nvs_ptr[3] = wl->mac_addr[5];
  262. /*
  263. * Layout before the actual NVS tables:
  264. * 1 byte : burst length.
  265. * 2 bytes: destination address.
  266. * n bytes: data to burst copy.
  267. *
  268. * This is ended by a 0 length, then the NVS tables.
  269. */
  270. /* FIXME: Do we need to check here whether the LSB is 1? */
  271. while (nvs_ptr[0]) {
  272. burst_len = nvs_ptr[0];
  273. dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
  274. /*
  275. * Due to our new wl1271_translate_reg_addr function,
  276. * we need to add the REGISTER_BASE to the destination
  277. */
  278. dest_addr += REGISTERS_BASE;
  279. /* We move our pointer to the data */
  280. nvs_ptr += 3;
  281. for (i = 0; i < burst_len; i++) {
  282. val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
  283. | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
  284. wl1271_debug(DEBUG_BOOT,
  285. "nvs burst write 0x%x: 0x%x",
  286. dest_addr, val);
  287. wl1271_write32(wl, dest_addr, val);
  288. nvs_ptr += 4;
  289. dest_addr += 4;
  290. }
  291. }
  292. /*
  293. * We've reached the first zero length, the first NVS table
  294. * is located at an aligned offset which is at least 7 bytes further.
  295. * NOTE: The wl->nvs->nvs element must be first, in order to
  296. * simplify the casting, we assume it is at the beginning of
  297. * the wl->nvs structure.
  298. */
  299. nvs_ptr = (u8 *)wl->nvs +
  300. ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
  301. nvs_len -= nvs_ptr - (u8 *)wl->nvs;
  302. /* Now we must set the partition correctly */
  303. wl1271_set_partition(wl, &part_table[PART_WORK]);
  304. /* Copy the NVS tables to a new block to ensure alignment */
  305. nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
  306. if (!nvs_aligned)
  307. return -ENOMEM;
  308. /* And finally we upload the NVS tables */
  309. wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
  310. kfree(nvs_aligned);
  311. return 0;
  312. }
  313. static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
  314. {
  315. wl1271_enable_interrupts(wl);
  316. wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
  317. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  318. wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
  319. }
  320. static int wl1271_boot_soft_reset(struct wl1271 *wl)
  321. {
  322. unsigned long timeout;
  323. u32 boot_data;
  324. /* perform soft reset */
  325. wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
  326. /* SOFT_RESET is self clearing */
  327. timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
  328. while (1) {
  329. boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
  330. wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
  331. if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
  332. break;
  333. if (time_after(jiffies, timeout)) {
  334. /* 1.2 check pWhalBus->uSelfClearTime if the
  335. * timeout was reached */
  336. wl1271_error("soft reset timeout");
  337. return -1;
  338. }
  339. udelay(SOFT_RESET_STALL_TIME);
  340. }
  341. /* disable Rx/Tx */
  342. wl1271_write32(wl, ENABLE, 0x0);
  343. /* disable auto calibration on start*/
  344. wl1271_write32(wl, SPARE_A2, 0xffff);
  345. return 0;
  346. }
  347. static int wl1271_boot_run_firmware(struct wl1271 *wl)
  348. {
  349. int loop, ret;
  350. u32 chip_id, intr;
  351. wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
  352. chip_id = wl1271_read32(wl, CHIP_ID_B);
  353. wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
  354. if (chip_id != wl->chip.id) {
  355. wl1271_error("chip id doesn't match after firmware boot");
  356. return -EIO;
  357. }
  358. /* wait for init to complete */
  359. loop = 0;
  360. while (loop++ < INIT_LOOP) {
  361. udelay(INIT_LOOP_DELAY);
  362. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  363. if (intr == 0xffffffff) {
  364. wl1271_error("error reading hardware complete "
  365. "init indication");
  366. return -EIO;
  367. }
  368. /* check that ACX_INTR_INIT_COMPLETE is enabled */
  369. else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
  370. wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
  371. WL1271_ACX_INTR_INIT_COMPLETE);
  372. break;
  373. }
  374. }
  375. if (loop > INIT_LOOP) {
  376. wl1271_error("timeout waiting for the hardware to "
  377. "complete initialization");
  378. return -EIO;
  379. }
  380. /* get hardware config command mail box */
  381. wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
  382. /* get hardware config event mail box */
  383. wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
  384. /* set the working partition to its "running" mode offset */
  385. wl1271_set_partition(wl, &part_table[PART_WORK]);
  386. wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
  387. wl->cmd_box_addr, wl->event_box_addr);
  388. wl1271_boot_fw_version(wl);
  389. /*
  390. * in case of full asynchronous mode the firmware event must be
  391. * ready to receive event from the command mailbox
  392. */
  393. /* unmask required mbox events */
  394. wl->event_mask = BSS_LOSE_EVENT_ID |
  395. SCAN_COMPLETE_EVENT_ID |
  396. PS_REPORT_EVENT_ID |
  397. JOIN_EVENT_COMPLETE_ID |
  398. DISCONNECT_EVENT_COMPLETE_ID |
  399. RSSI_SNR_TRIGGER_0_EVENT_ID |
  400. PSPOLL_DELIVERY_FAILURE_EVENT_ID |
  401. SOFT_GEMINI_SENSE_EVENT_ID;
  402. if (wl->bss_type == BSS_TYPE_AP_BSS)
  403. wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID;
  404. else
  405. wl->event_mask |= DUMMY_PACKET_EVENT_ID;
  406. ret = wl1271_event_unmask(wl);
  407. if (ret < 0) {
  408. wl1271_error("EVENT mask setting failed");
  409. return ret;
  410. }
  411. wl1271_event_mbox_config(wl);
  412. /* firmware startup completed */
  413. return 0;
  414. }
  415. static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
  416. {
  417. u32 polarity;
  418. polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
  419. /* We use HIGH polarity, so unset the LOW bit */
  420. polarity &= ~POLARITY_LOW;
  421. wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
  422. return 0;
  423. }
  424. static void wl1271_boot_hw_version(struct wl1271 *wl)
  425. {
  426. u32 fuse;
  427. fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1);
  428. fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET;
  429. wl->hw_pg_ver = (s8)fuse;
  430. if (((wl->hw_pg_ver & PG_MAJOR_VER_MASK) >> PG_MAJOR_VER_OFFSET) < 3)
  431. wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
  432. }
  433. /*
  434. * WL128x has two clocks input - TCXO and FREF.
  435. * TCXO is the main clock of the device, while FREF is used to sync
  436. * between the GPS and the cellular modem.
  437. * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used
  438. * as the WLAN/BT main clock.
  439. */
  440. static int wl128x_switch_fref(struct wl1271 *wl, bool *is_ref_clk)
  441. {
  442. u16 sys_clk_cfg_val;
  443. /* if working on XTAL-only mode go directly to TCXO TO FREF SWITCH */
  444. if ((wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL) ||
  445. (wl->ref_clock == CONF_REF_CLK_26_M_XTAL))
  446. return true;
  447. /* Read clock source FREF or TCXO */
  448. sys_clk_cfg_val = wl1271_top_reg_read(wl, SYS_CLK_CFG_REG);
  449. if (sys_clk_cfg_val & PRCM_CM_EN_MUX_WLAN_FREF) {
  450. /* if bit 3 is set - working with FREF clock */
  451. wl1271_debug(DEBUG_BOOT, "working with FREF clock, skip"
  452. " to FREF");
  453. *is_ref_clk = true;
  454. } else {
  455. /* if bit 3 is clear - working with TCXO clock */
  456. wl1271_debug(DEBUG_BOOT, "working with TCXO clock");
  457. /* TCXO to FREF switch, check TXCO clock config */
  458. if ((wl->tcxo_clock != WL12XX_TCXOCLOCK_16_368) &&
  459. (wl->tcxo_clock != WL12XX_TCXOCLOCK_32_736)) {
  460. /*
  461. * not 16.368Mhz and not 32.736Mhz - skip to
  462. * configure ELP stage
  463. */
  464. wl1271_debug(DEBUG_BOOT, "NEW PLL ALGO:"
  465. " TcxoRefClk=%d - not 16.368Mhz and not"
  466. " 32.736Mhz - skip to configure ELP"
  467. " stage", wl->tcxo_clock);
  468. *is_ref_clk = false;
  469. } else {
  470. wl1271_debug(DEBUG_BOOT, "NEW PLL ALGO:"
  471. "TcxoRefClk=%d - 16.368Mhz or 32.736Mhz"
  472. " - TCXO to FREF switch",
  473. wl->tcxo_clock);
  474. return true;
  475. }
  476. }
  477. return false;
  478. }
  479. static int wl128x_boot_clk(struct wl1271 *wl, bool *is_ref_clk)
  480. {
  481. if (wl128x_switch_fref(wl, is_ref_clk)) {
  482. wl1271_debug(DEBUG_BOOT, "XTAL-only mode go directly to"
  483. " TCXO TO FREF SWITCH");
  484. /* TCXO to FREF switch - for PG2.0 */
  485. wl1271_top_reg_write(wl, WL_SPARE_REG,
  486. WL_SPARE_MASK_8526);
  487. wl1271_top_reg_write(wl, SYS_CLK_CFG_REG,
  488. WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF);
  489. *is_ref_clk = true;
  490. mdelay(15);
  491. }
  492. /* Set bit 2 in spare register to avoid illegal access */
  493. wl1271_top_reg_write(wl, WL_SPARE_REG, WL_SPARE_VAL);
  494. /* working with TCXO clock */
  495. if ((*is_ref_clk == false) &&
  496. ((wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8) ||
  497. (wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6))) {
  498. wl1271_debug(DEBUG_BOOT, "16_8_M or 33_6_M TCXO detected");
  499. /* Manually Configure MCS PLL settings PG2.0 Only */
  500. wl1271_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL);
  501. wl1271_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL);
  502. wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG,
  503. MCS_PLL_CONFIG_REG_VAL);
  504. } else {
  505. int pll_config;
  506. u16 mcs_pll_config_val;
  507. /*
  508. * Configure MCS PLL settings to FREF Freq
  509. * Set the values that determine the time elapse since the PLL's
  510. * get their enable signal until the lock indication is set
  511. */
  512. wl1271_top_reg_write(wl, PLL_LOCK_COUNTERS_REG,
  513. PLL_LOCK_COUNTERS_COEX | PLL_LOCK_COUNTERS_MCS);
  514. mcs_pll_config_val = wl1271_top_reg_read(wl,
  515. MCS_PLL_CONFIG_REG);
  516. /*
  517. * Set the MCS PLL input frequency value according to the
  518. * reference clock value detected/read
  519. */
  520. if (*is_ref_clk == false) {
  521. if ((wl->tcxo_clock == WL12XX_TCXOCLOCK_19_2) ||
  522. (wl->tcxo_clock == WL12XX_TCXOCLOCK_38_4))
  523. pll_config = 1;
  524. else if ((wl->tcxo_clock == WL12XX_TCXOCLOCK_26)
  525. ||
  526. (wl->tcxo_clock == WL12XX_TCXOCLOCK_52))
  527. pll_config = 2;
  528. else
  529. return -EINVAL;
  530. } else {
  531. if ((wl->ref_clock == CONF_REF_CLK_19_2_E) ||
  532. (wl->ref_clock == CONF_REF_CLK_38_4_E))
  533. pll_config = 1;
  534. else if ((wl->ref_clock == CONF_REF_CLK_26_E) ||
  535. (wl->ref_clock == CONF_REF_CLK_52_E))
  536. pll_config = 2;
  537. else
  538. return -EINVAL;
  539. }
  540. mcs_pll_config_val |= (pll_config << (MCS_SEL_IN_FREQ_SHIFT)) &
  541. (MCS_SEL_IN_FREQ_MASK);
  542. wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG,
  543. mcs_pll_config_val);
  544. }
  545. return 0;
  546. }
  547. static int wl127x_boot_clk(struct wl1271 *wl)
  548. {
  549. u32 pause;
  550. u32 clk;
  551. wl1271_boot_hw_version(wl);
  552. if (wl->ref_clock == CONF_REF_CLK_19_2_E ||
  553. wl->ref_clock == CONF_REF_CLK_38_4_E ||
  554. wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
  555. /* ref clk: 19.2/38.4/38.4-XTAL */
  556. clk = 0x3;
  557. else if (wl->ref_clock == CONF_REF_CLK_26_E ||
  558. wl->ref_clock == CONF_REF_CLK_52_E)
  559. /* ref clk: 26/52 */
  560. clk = 0x5;
  561. else
  562. return -EINVAL;
  563. if (wl->ref_clock != CONF_REF_CLK_19_2_E) {
  564. u16 val;
  565. /* Set clock type (open drain) */
  566. val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
  567. val &= FREF_CLK_TYPE_BITS;
  568. wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
  569. /* Set clock pull mode (no pull) */
  570. val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL);
  571. val |= NO_PULL;
  572. wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val);
  573. } else {
  574. u16 val;
  575. /* Set clock polarity */
  576. val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
  577. val &= FREF_CLK_POLARITY_BITS;
  578. val |= CLK_REQ_OUTN_SEL;
  579. wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
  580. }
  581. wl1271_write32(wl, PLL_PARAMETERS, clk);
  582. pause = wl1271_read32(wl, PLL_PARAMETERS);
  583. wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
  584. pause &= ~(WU_COUNTER_PAUSE_VAL);
  585. pause |= WU_COUNTER_PAUSE_VAL;
  586. wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
  587. return 0;
  588. }
  589. /* uploads NVS and firmware */
  590. int wl1271_load_firmware(struct wl1271 *wl)
  591. {
  592. int ret = 0;
  593. u32 tmp, clk;
  594. bool is_ref_clk = false;
  595. if (wl->chip.id == CHIP_ID_1283_PG20) {
  596. ret = wl128x_boot_clk(wl, &is_ref_clk);
  597. if (ret < 0)
  598. goto out;
  599. } else {
  600. ret = wl127x_boot_clk(wl);
  601. if (ret < 0)
  602. goto out;
  603. }
  604. /* Continue the ELP wake up sequence */
  605. wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
  606. udelay(500);
  607. wl1271_set_partition(wl, &part_table[PART_DRPW]);
  608. /* Read-modify-write DRPW_SCRATCH_START register (see next state)
  609. to be used by DRPw FW. The RTRIM value will be added by the FW
  610. before taking DRPw out of reset */
  611. wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
  612. clk = wl1271_read32(wl, DRPW_SCRATCH_START);
  613. wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
  614. if (wl->chip.id == CHIP_ID_1283_PG20) {
  615. if (is_ref_clk == false)
  616. clk |= ((wl->tcxo_clock & 0x3) << 1) << 4;
  617. else
  618. clk |= ((wl->ref_clock & 0x3) << 1) << 4;
  619. } else {
  620. clk |= (wl->ref_clock << 1) << 4;
  621. }
  622. wl1271_write32(wl, DRPW_SCRATCH_START, clk);
  623. wl1271_set_partition(wl, &part_table[PART_WORK]);
  624. /* Disable interrupts */
  625. wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  626. ret = wl1271_boot_soft_reset(wl);
  627. if (ret < 0)
  628. goto out;
  629. /* 2. start processing NVS file */
  630. ret = wl1271_boot_upload_nvs(wl);
  631. if (ret < 0)
  632. goto out;
  633. /* write firmware's last address (ie. it's length) to
  634. * ACX_EEPROMLESS_IND_REG */
  635. wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
  636. wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
  637. tmp = wl1271_read32(wl, CHIP_ID_B);
  638. wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
  639. /* 6. read the EEPROM parameters */
  640. tmp = wl1271_read32(wl, SCR_PAD2);
  641. /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
  642. * to upload_fw) */
  643. if (wl->chip.id == CHIP_ID_1283_PG20)
  644. wl1271_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA);
  645. ret = wl1271_boot_upload_firmware(wl);
  646. if (ret < 0)
  647. goto out;
  648. out:
  649. return ret;
  650. }
  651. EXPORT_SYMBOL_GPL(wl1271_load_firmware);
  652. int wl1271_boot(struct wl1271 *wl)
  653. {
  654. int ret;
  655. /* upload NVS and firmware */
  656. ret = wl1271_load_firmware(wl);
  657. if (ret)
  658. return ret;
  659. /* 10.5 start firmware */
  660. ret = wl1271_boot_run_firmware(wl);
  661. if (ret < 0)
  662. goto out;
  663. ret = wl1271_boot_write_irq_polarity(wl);
  664. if (ret < 0)
  665. goto out;
  666. wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
  667. WL1271_ACX_ALL_EVENTS_VECTOR);
  668. /* Enable firmware interrupts now */
  669. wl1271_boot_enable_interrupts(wl);
  670. /* set the wl1271 default filters */
  671. wl1271_set_default_filters(wl);
  672. wl1271_event_mbox_config(wl);
  673. out:
  674. return ret;
  675. }