main.c 10 KB

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