main.c 11 KB

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