boot.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. *
  6. * Contact: Kalle Valo <kalle.valo@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/gpio.h>
  24. #include "reg.h"
  25. #include "boot.h"
  26. #include "spi.h"
  27. #include "event.h"
  28. static void wl12xx_boot_enable_interrupts(struct wl12xx *wl)
  29. {
  30. enable_irq(wl->irq);
  31. }
  32. void wl12xx_boot_target_enable_interrupts(struct wl12xx *wl)
  33. {
  34. wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
  35. wl12xx_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
  36. }
  37. int wl12xx_boot_soft_reset(struct wl12xx *wl)
  38. {
  39. unsigned long timeout;
  40. u32 boot_data;
  41. /* perform soft reset */
  42. wl12xx_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
  43. /* SOFT_RESET is self clearing */
  44. timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
  45. while (1) {
  46. boot_data = wl12xx_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
  47. wl12xx_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
  48. if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
  49. break;
  50. if (time_after(jiffies, timeout)) {
  51. /* 1.2 check pWhalBus->uSelfClearTime if the
  52. * timeout was reached */
  53. wl12xx_error("soft reset timeout");
  54. return -1;
  55. }
  56. udelay(SOFT_RESET_STALL_TIME);
  57. }
  58. /* disable Rx/Tx */
  59. wl12xx_reg_write32(wl, ENABLE, 0x0);
  60. /* disable auto calibration on start*/
  61. wl12xx_reg_write32(wl, SPARE_A2, 0xffff);
  62. return 0;
  63. }
  64. int wl12xx_boot_init_seq(struct wl12xx *wl)
  65. {
  66. u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
  67. /*
  68. * col #1: INTEGER_DIVIDER
  69. * col #2: FRACTIONAL_DIVIDER
  70. * col #3: ATTN_BB
  71. * col #4: ALPHA_BB
  72. * col #5: STOP_TIME_BB
  73. * col #6: BB_PLL_LOOP_FILTER
  74. */
  75. static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
  76. { 83, 87381, 0xB, 5, 0xF00, 3}, /* REF_FREQ_19_2*/
  77. { 61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
  78. { 41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
  79. { 40, 0, 0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
  80. { 47, 162280, 0xC, 6, 0x2760, 1} /* REF_FREQ_33_6 */
  81. };
  82. /* read NVS params */
  83. scr_pad6 = wl12xx_reg_read32(wl, SCR_PAD6);
  84. wl12xx_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
  85. /* read ELP_CMD */
  86. elp_cmd = wl12xx_reg_read32(wl, ELP_CMD);
  87. wl12xx_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
  88. /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
  89. ref_freq = scr_pad6 & 0x000000FF;
  90. wl12xx_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
  91. wl12xx_reg_write32(wl, PLL_CAL_TIME, 0x9);
  92. /*
  93. * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
  94. */
  95. wl12xx_reg_write32(wl, CLK_BUF_TIME, 0x6);
  96. /*
  97. * set the clock detect feature to work in the restart wu procedure
  98. * (ELP_CFG_MODE[14]) and Select the clock source type
  99. * (ELP_CFG_MODE[13:12])
  100. */
  101. tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
  102. wl12xx_reg_write32(wl, ELP_CFG_MODE, tmp);
  103. /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
  104. elp_cmd |= 0x00000040;
  105. wl12xx_reg_write32(wl, ELP_CMD, elp_cmd);
  106. /* PG 1.2: Set the BB PLL stable time to be 1000usec
  107. * (PLL_STABLE_TIME) */
  108. wl12xx_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
  109. /* PG 1.2: read clock request time */
  110. init_data = wl12xx_reg_read32(wl, CLK_REQ_TIME);
  111. /*
  112. * PG 1.2: set the clock request time to be ref_clk_settling_time -
  113. * 1ms = 4ms
  114. */
  115. if (init_data > 0x21)
  116. tmp = init_data - 0x21;
  117. else
  118. tmp = 0;
  119. wl12xx_reg_write32(wl, CLK_REQ_TIME, tmp);
  120. /* set BB PLL configurations in RF AFE */
  121. wl12xx_reg_write32(wl, 0x003058cc, 0x4B5);
  122. /* set RF_AFE_REG_5 */
  123. wl12xx_reg_write32(wl, 0x003058d4, 0x50);
  124. /* set RF_AFE_CTRL_REG_2 */
  125. wl12xx_reg_write32(wl, 0x00305948, 0x11c001);
  126. /*
  127. * change RF PLL and BB PLL divider for VCO clock and adjust VCO
  128. * bais current(RF_AFE_REG_13)
  129. */
  130. wl12xx_reg_write32(wl, 0x003058f4, 0x1e);
  131. /* set BB PLL configurations */
  132. tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
  133. wl12xx_reg_write32(wl, 0x00305840, tmp);
  134. /* set fractional divider according to Appendix C-BB PLL
  135. * Calculations
  136. */
  137. tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
  138. wl12xx_reg_write32(wl, 0x00305844, tmp);
  139. /* set the initial data for the sigma delta */
  140. wl12xx_reg_write32(wl, 0x00305848, 0x3039);
  141. /*
  142. * set the accumulator attenuation value, calibration loop1
  143. * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
  144. * the VCO gain
  145. */
  146. tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
  147. (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
  148. wl12xx_reg_write32(wl, 0x00305854, tmp);
  149. /*
  150. * set the calibration stop time after holdoff time expires and set
  151. * settling time HOLD_OFF_TIME_BB
  152. */
  153. tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
  154. wl12xx_reg_write32(wl, 0x00305858, tmp);
  155. /*
  156. * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
  157. * constant leakage current to linearize PFD to 0uA -
  158. * BB_ILOOPF[7:3]
  159. */
  160. tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
  161. wl12xx_reg_write32(wl, 0x003058f8, tmp);
  162. /*
  163. * set regulator output voltage for n divider to
  164. * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
  165. * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
  166. * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
  167. */
  168. wl12xx_reg_write32(wl, 0x003058f0, 0x29);
  169. /* enable restart wakeup sequence (ELP_CMD[0]) */
  170. wl12xx_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
  171. /* restart sequence completed */
  172. udelay(2000);
  173. return 0;
  174. }
  175. int wl12xx_boot_run_firmware(struct wl12xx *wl)
  176. {
  177. int loop, ret;
  178. u32 chip_id, interrupt;
  179. wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
  180. chip_id = wl12xx_reg_read32(wl, CHIP_ID_B);
  181. wl12xx_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
  182. if (chip_id != wl->chip.id) {
  183. wl12xx_error("chip id doesn't match after firmware boot");
  184. return -EIO;
  185. }
  186. /* wait for init to complete */
  187. loop = 0;
  188. while (loop++ < INIT_LOOP) {
  189. udelay(INIT_LOOP_DELAY);
  190. interrupt = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  191. if (interrupt == 0xffffffff) {
  192. wl12xx_error("error reading hardware complete "
  193. "init indication");
  194. return -EIO;
  195. }
  196. /* check that ACX_INTR_INIT_COMPLETE is enabled */
  197. else if (interrupt & wl->chip.intr_init_complete) {
  198. wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
  199. wl->chip.intr_init_complete);
  200. break;
  201. }
  202. }
  203. if (loop >= INIT_LOOP) {
  204. wl12xx_error("timeout waiting for the hardware to "
  205. "complete initialization");
  206. return -EIO;
  207. }
  208. /* get hardware config command mail box */
  209. wl->cmd_box_addr = wl12xx_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
  210. /* get hardware config event mail box */
  211. wl->event_box_addr = wl12xx_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
  212. /* set the working partition to its "running" mode offset */
  213. wl12xx_set_partition(wl,
  214. wl->chip.p_table[PART_WORK].mem.start,
  215. wl->chip.p_table[PART_WORK].mem.size,
  216. wl->chip.p_table[PART_WORK].reg.start,
  217. wl->chip.p_table[PART_WORK].reg.size);
  218. wl12xx_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
  219. wl->cmd_box_addr, wl->event_box_addr);
  220. /*
  221. * in case of full asynchronous mode the firmware event must be
  222. * ready to receive event from the command mailbox
  223. */
  224. /* enable gpio interrupts */
  225. wl12xx_boot_enable_interrupts(wl);
  226. wl->chip.op_target_enable_interrupts(wl);
  227. /* unmask all mbox events */
  228. wl->event_mask = 0xffffffff;
  229. ret = wl12xx_event_unmask(wl);
  230. if (ret < 0) {
  231. wl12xx_error("EVENT mask setting failed");
  232. return ret;
  233. }
  234. wl12xx_event_mbox_config(wl);
  235. /* firmware startup completed */
  236. return 0;
  237. }