main.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include "../wlcore/wlcore.h"
  24. #include "../wlcore/debug.h"
  25. #include "../wlcore/io.h"
  26. #include "../wlcore/acx.h"
  27. #include "../wlcore/boot.h"
  28. #include "reg.h"
  29. #include "conf.h"
  30. #include "wl18xx.h"
  31. static struct wl18xx_conf wl18xx_default_conf = {
  32. .phy = {
  33. .phy_standalone = 0x00,
  34. .primary_clock_setting_time = 0x05,
  35. .clock_valid_on_wake_up = 0x00,
  36. .secondary_clock_setting_time = 0x05,
  37. .rdl = 0x01,
  38. .auto_detect = 0x00,
  39. .dedicated_fem = FEM_NONE,
  40. .low_band_component = COMPONENT_2_WAY_SWITCH,
  41. .low_band_component_type = 0x05,
  42. .high_band_component = COMPONENT_2_WAY_SWITCH,
  43. .high_band_component_type = 0x09,
  44. .number_of_assembled_ant2_4 = 0x01,
  45. .number_of_assembled_ant5 = 0x01,
  46. .external_pa_dc2dc = 0x00,
  47. .tcxo_ldo_voltage = 0x00,
  48. .xtal_itrim_val = 0x04,
  49. .srf_state = 0x00,
  50. .io_configuration = 0x01,
  51. .sdio_configuration = 0x00,
  52. .settings = 0x00,
  53. .enable_clpc = 0x00,
  54. .enable_tx_low_pwr_on_siso_rdl = 0x00,
  55. .rx_profile = 0x00,
  56. },
  57. };
  58. static const struct wlcore_partition_set wl18xx_ptable[PART_TABLE_LEN] = {
  59. [PART_TOP_PRCM_ELP_SOC] = {
  60. .mem = { .start = 0x00A02000, .size = 0x00010000 },
  61. .reg = { .start = 0x00807000, .size = 0x00005000 },
  62. .mem2 = { .start = 0x00800000, .size = 0x0000B000 },
  63. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  64. },
  65. [PART_DOWN] = {
  66. .mem = { .start = 0x00000000, .size = 0x00014000 },
  67. .reg = { .start = 0x00810000, .size = 0x0000BFFF },
  68. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  69. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  70. },
  71. [PART_BOOT] = {
  72. .mem = { .start = 0x00700000, .size = 0x0000030c },
  73. .reg = { .start = 0x00802000, .size = 0x00014578 },
  74. .mem2 = { .start = 0x00B00404, .size = 0x00001000 },
  75. .mem3 = { .start = 0x00C00000, .size = 0x00000400 },
  76. },
  77. [PART_WORK] = {
  78. .mem = { .start = 0x00800000, .size = 0x000050FC },
  79. .reg = { .start = 0x00B00404, .size = 0x00001000 },
  80. .mem2 = { .start = 0x00C00000, .size = 0x00000400 },
  81. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  82. },
  83. [PART_PHY_INIT] = {
  84. /* TODO: use the phy_conf struct size here */
  85. .mem = { .start = 0x80926000, .size = 252 },
  86. .reg = { .start = 0x00000000, .size = 0x00000000 },
  87. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  88. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  89. },
  90. };
  91. static const int wl18xx_rtable[REG_TABLE_LEN] = {
  92. [REG_ECPU_CONTROL] = WL18XX_REG_ECPU_CONTROL,
  93. [REG_INTERRUPT_NO_CLEAR] = WL18XX_REG_INTERRUPT_NO_CLEAR,
  94. [REG_INTERRUPT_ACK] = WL18XX_REG_INTERRUPT_ACK,
  95. [REG_COMMAND_MAILBOX_PTR] = WL18XX_REG_COMMAND_MAILBOX_PTR,
  96. [REG_EVENT_MAILBOX_PTR] = WL18XX_REG_EVENT_MAILBOX_PTR,
  97. [REG_INTERRUPT_TRIG] = WL18XX_REG_INTERRUPT_TRIG_H,
  98. [REG_INTERRUPT_MASK] = WL18XX_REG_INTERRUPT_MASK,
  99. [REG_PC_ON_RECOVERY] = 0, /* TODO: where is the PC? */
  100. [REG_CHIP_ID_B] = WL18XX_REG_CHIP_ID_B,
  101. [REG_CMD_MBOX_ADDRESS] = WL18XX_CMD_MBOX_ADDRESS,
  102. /* data access memory addresses, used with partition translation */
  103. [REG_SLV_MEM_DATA] = WL18XX_SLV_MEM_DATA,
  104. [REG_SLV_REG_DATA] = WL18XX_SLV_REG_DATA,
  105. /* raw data access memory addresses */
  106. [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
  107. };
  108. /* TODO: maybe move to a new header file? */
  109. #define WL18XX_FW_NAME "ti-connectivity/wl18xx-fw.bin"
  110. static int wl18xx_identify_chip(struct wl1271 *wl)
  111. {
  112. int ret = 0;
  113. switch (wl->chip.id) {
  114. case CHIP_ID_185x_PG10:
  115. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG10)",
  116. wl->chip.id);
  117. wl->sr_fw_name = WL18XX_FW_NAME;
  118. wl->quirks |= WLCORE_QUIRK_NO_ELP;
  119. /* TODO: need to blocksize alignment for RX/TX separately? */
  120. break;
  121. default:
  122. wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
  123. ret = -ENODEV;
  124. goto out;
  125. }
  126. out:
  127. return ret;
  128. }
  129. static void wl18xx_set_clk(struct wl1271 *wl)
  130. {
  131. /*
  132. * TODO: this is hardcoded just for DVP/EVB, fix according to
  133. * new unified_drv.
  134. */
  135. wl1271_write32(wl, WL18XX_SCR_PAD2, 0xB3);
  136. wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  137. wl1271_write32(wl, 0x00A02360, 0xD0078);
  138. wl1271_write32(wl, 0x00A0236c, 0x12);
  139. wl1271_write32(wl, 0x00A02390, 0x20118);
  140. }
  141. static void wl18xx_boot_soft_reset(struct wl1271 *wl)
  142. {
  143. /* disable Rx/Tx */
  144. wl1271_write32(wl, WL18XX_ENABLE, 0x0);
  145. /* disable auto calibration on start*/
  146. wl1271_write32(wl, WL18XX_SPARE_A2, 0xffff);
  147. }
  148. static int wl18xx_pre_boot(struct wl1271 *wl)
  149. {
  150. /* TODO: add hw_pg_ver reading */
  151. wl18xx_set_clk(wl);
  152. /* Continue the ELP wake up sequence */
  153. wl1271_write32(wl, WL18XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
  154. udelay(500);
  155. wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  156. /* Disable interrupts */
  157. wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  158. wl18xx_boot_soft_reset(wl);
  159. return 0;
  160. }
  161. static void wl18xx_pre_upload(struct wl1271 *wl)
  162. {
  163. u32 tmp;
  164. wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  165. /* TODO: check if this is all needed */
  166. wl1271_write32(wl, WL18XX_EEPROMLESS_IND, WL18XX_EEPROMLESS_IND);
  167. tmp = wlcore_read_reg(wl, REG_CHIP_ID_B);
  168. wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
  169. tmp = wl1271_read32(wl, WL18XX_SCR_PAD2);
  170. }
  171. static void wl18xx_set_mac_and_phy(struct wl1271 *wl)
  172. {
  173. struct wl18xx_mac_and_phy_params params;
  174. memset(&params, 0, sizeof(params));
  175. params.phy_standalone = wl18xx_default_conf.phy.phy_standalone;
  176. params.rdl = wl18xx_default_conf.phy.rdl;
  177. params.enable_clpc = wl18xx_default_conf.phy.enable_clpc;
  178. params.enable_tx_low_pwr_on_siso_rdl =
  179. wl18xx_default_conf.phy.enable_tx_low_pwr_on_siso_rdl;
  180. params.auto_detect = wl18xx_default_conf.phy.auto_detect;
  181. params.dedicated_fem = wl18xx_default_conf.phy.dedicated_fem;
  182. params.low_band_component = wl18xx_default_conf.phy.low_band_component;
  183. params.low_band_component_type =
  184. wl18xx_default_conf.phy.low_band_component_type;
  185. params.high_band_component =
  186. wl18xx_default_conf.phy.high_band_component;
  187. params.high_band_component_type =
  188. wl18xx_default_conf.phy.high_band_component_type;
  189. params.number_of_assembled_ant2_4 =
  190. wl18xx_default_conf.phy.number_of_assembled_ant2_4;
  191. params.number_of_assembled_ant5 =
  192. wl18xx_default_conf.phy.number_of_assembled_ant5;
  193. params.external_pa_dc2dc = wl18xx_default_conf.phy.external_pa_dc2dc;
  194. params.tcxo_ldo_voltage = wl18xx_default_conf.phy.tcxo_ldo_voltage;
  195. params.xtal_itrim_val = wl18xx_default_conf.phy.xtal_itrim_val;
  196. params.srf_state = wl18xx_default_conf.phy.srf_state;
  197. params.io_configuration = wl18xx_default_conf.phy.io_configuration;
  198. params.sdio_configuration = wl18xx_default_conf.phy.sdio_configuration;
  199. params.settings = wl18xx_default_conf.phy.settings;
  200. params.rx_profile = wl18xx_default_conf.phy.rx_profile;
  201. params.primary_clock_setting_time =
  202. wl18xx_default_conf.phy.primary_clock_setting_time;
  203. params.clock_valid_on_wake_up =
  204. wl18xx_default_conf.phy.clock_valid_on_wake_up;
  205. params.secondary_clock_setting_time =
  206. wl18xx_default_conf.phy.secondary_clock_setting_time;
  207. /* TODO: hardcoded for now */
  208. params.board_type = BOARD_TYPE_DVP_EVB_18XX;
  209. wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  210. wl1271_write(wl, WL18XX_PHY_INIT_MEM_ADDR, (u8 *)&params,
  211. sizeof(params), false);
  212. }
  213. static void wl18xx_enable_interrupts(struct wl1271 *wl)
  214. {
  215. wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR);
  216. wlcore_enable_interrupts(wl);
  217. wlcore_write_reg(wl, REG_INTERRUPT_MASK,
  218. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  219. }
  220. static int wl18xx_boot(struct wl1271 *wl)
  221. {
  222. int ret;
  223. ret = wl18xx_pre_boot(wl);
  224. if (ret < 0)
  225. goto out;
  226. ret = wlcore_boot_upload_nvs(wl);
  227. if (ret < 0)
  228. goto out;
  229. wl18xx_pre_upload(wl);
  230. ret = wlcore_boot_upload_firmware(wl);
  231. if (ret < 0)
  232. goto out;
  233. wl18xx_set_mac_and_phy(wl);
  234. ret = wlcore_boot_run_firmware(wl);
  235. if (ret < 0)
  236. goto out;
  237. wl18xx_enable_interrupts(wl);
  238. out:
  239. return ret;
  240. }
  241. static void wl18xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
  242. void *buf, size_t len)
  243. {
  244. struct wl18xx_priv *priv = wl->priv;
  245. memcpy(priv->cmd_buf, buf, len);
  246. memset(priv->cmd_buf + len, 0, WL18XX_CMD_MAX_SIZE - len);
  247. wl1271_write(wl, cmd_box_addr, priv->cmd_buf, WL18XX_CMD_MAX_SIZE,
  248. false);
  249. }
  250. static void wl18xx_ack_event(struct wl1271 *wl)
  251. {
  252. wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL18XX_INTR_TRIG_EVENT_ACK);
  253. }
  254. static struct wlcore_ops wl18xx_ops = {
  255. .identify_chip = wl18xx_identify_chip,
  256. .boot = wl18xx_boot,
  257. .trigger_cmd = wl18xx_trigger_cmd,
  258. .ack_event = wl18xx_ack_event,
  259. };
  260. int __devinit wl18xx_probe(struct platform_device *pdev)
  261. {
  262. struct wl1271 *wl;
  263. struct ieee80211_hw *hw;
  264. struct wl18xx_priv *priv;
  265. hw = wlcore_alloc_hw(sizeof(*priv));
  266. if (IS_ERR(hw)) {
  267. wl1271_error("can't allocate hw");
  268. return PTR_ERR(hw);
  269. }
  270. wl = hw->priv;
  271. wl->ops = &wl18xx_ops;
  272. wl->ptable = wl18xx_ptable;
  273. wl->rtable = wl18xx_rtable;
  274. return wlcore_probe(wl, pdev);
  275. }
  276. static const struct platform_device_id wl18xx_id_table[] __devinitconst = {
  277. { "wl18xx", 0 },
  278. { } /* Terminating Entry */
  279. };
  280. MODULE_DEVICE_TABLE(platform, wl18xx_id_table);
  281. static struct platform_driver wl18xx_driver = {
  282. .probe = wl18xx_probe,
  283. .remove = __devexit_p(wlcore_remove),
  284. .id_table = wl18xx_id_table,
  285. .driver = {
  286. .name = "wl18xx_driver",
  287. .owner = THIS_MODULE,
  288. }
  289. };
  290. static int __init wl18xx_init(void)
  291. {
  292. return platform_driver_register(&wl18xx_driver);
  293. }
  294. module_init(wl18xx_init);
  295. static void __exit wl18xx_exit(void)
  296. {
  297. platform_driver_unregister(&wl18xx_driver);
  298. }
  299. module_exit(wl18xx_exit);
  300. MODULE_LICENSE("GPL v2");
  301. MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
  302. MODULE_FIRMWARE(WL18XX_FW_NAME);