main.c 11 KB

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