cmd.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. * Copyright (C) 2011 Texas Instruments Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include "../wlcore/cmd.h"
  23. #include "../wlcore/debug.h"
  24. #include "cmd.h"
  25. int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
  26. {
  27. struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
  28. struct conf_rf_settings *rf = &wl->conf.rf;
  29. int ret;
  30. if (!wl->nvs)
  31. return -ENODEV;
  32. ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
  33. if (!ext_radio_parms)
  34. return -ENOMEM;
  35. ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
  36. memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
  37. rf->tx_per_channel_power_compensation_2,
  38. CONF_TX_PWR_COMPENSATION_LEN_2);
  39. memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
  40. rf->tx_per_channel_power_compensation_5,
  41. CONF_TX_PWR_COMPENSATION_LEN_5);
  42. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
  43. ext_radio_parms, sizeof(*ext_radio_parms));
  44. ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
  45. if (ret < 0)
  46. wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
  47. kfree(ext_radio_parms);
  48. return ret;
  49. }
  50. int wl1271_cmd_general_parms(struct wl1271 *wl)
  51. {
  52. struct wl1271_general_parms_cmd *gen_parms;
  53. struct wl1271_ini_general_params *gp =
  54. &((struct wl1271_nvs_file *)wl->nvs)->general_params;
  55. bool answer = false;
  56. int ret;
  57. if (!wl->nvs)
  58. return -ENODEV;
  59. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  60. wl1271_warning("FEM index from INI out of bounds");
  61. return -EINVAL;
  62. }
  63. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  64. if (!gen_parms)
  65. return -ENOMEM;
  66. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  67. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  68. if (gp->tx_bip_fem_auto_detect)
  69. answer = true;
  70. /* Override the REF CLK from the NVS with the one from platform data */
  71. gen_parms->general_params.ref_clock = wl->ref_clock;
  72. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  73. if (ret < 0) {
  74. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  75. goto out;
  76. }
  77. gp->tx_bip_fem_manufacturer =
  78. gen_parms->general_params.tx_bip_fem_manufacturer;
  79. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  80. wl1271_warning("FEM index from FW out of bounds");
  81. ret = -EINVAL;
  82. goto out;
  83. }
  84. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  85. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  86. out:
  87. kfree(gen_parms);
  88. return ret;
  89. }
  90. int wl128x_cmd_general_parms(struct wl1271 *wl)
  91. {
  92. struct wl128x_general_parms_cmd *gen_parms;
  93. struct wl128x_ini_general_params *gp =
  94. &((struct wl128x_nvs_file *)wl->nvs)->general_params;
  95. bool answer = false;
  96. int ret;
  97. if (!wl->nvs)
  98. return -ENODEV;
  99. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  100. wl1271_warning("FEM index from ini out of bounds");
  101. return -EINVAL;
  102. }
  103. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  104. if (!gen_parms)
  105. return -ENOMEM;
  106. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  107. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  108. if (gp->tx_bip_fem_auto_detect)
  109. answer = true;
  110. /* Replace REF and TCXO CLKs with the ones from platform data */
  111. gen_parms->general_params.ref_clock = wl->ref_clock;
  112. gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
  113. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  114. if (ret < 0) {
  115. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  116. goto out;
  117. }
  118. gp->tx_bip_fem_manufacturer =
  119. gen_parms->general_params.tx_bip_fem_manufacturer;
  120. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  121. wl1271_warning("FEM index from FW out of bounds");
  122. ret = -EINVAL;
  123. goto out;
  124. }
  125. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  126. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  127. out:
  128. kfree(gen_parms);
  129. return ret;
  130. }
  131. int wl1271_cmd_radio_parms(struct wl1271 *wl)
  132. {
  133. struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
  134. struct wl1271_radio_parms_cmd *radio_parms;
  135. struct wl1271_ini_general_params *gp = &nvs->general_params;
  136. int ret;
  137. if (!wl->nvs)
  138. return -ENODEV;
  139. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  140. if (!radio_parms)
  141. return -ENOMEM;
  142. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  143. /* 2.4GHz parameters */
  144. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  145. sizeof(struct wl1271_ini_band_params_2));
  146. memcpy(&radio_parms->dyn_params_2,
  147. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  148. sizeof(struct wl1271_ini_fem_params_2));
  149. /* 5GHz parameters */
  150. memcpy(&radio_parms->static_params_5,
  151. &nvs->stat_radio_params_5,
  152. sizeof(struct wl1271_ini_band_params_5));
  153. memcpy(&radio_parms->dyn_params_5,
  154. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  155. sizeof(struct wl1271_ini_fem_params_5));
  156. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  157. radio_parms, sizeof(*radio_parms));
  158. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  159. if (ret < 0)
  160. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  161. kfree(radio_parms);
  162. return ret;
  163. }
  164. int wl128x_cmd_radio_parms(struct wl1271 *wl)
  165. {
  166. struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
  167. struct wl128x_radio_parms_cmd *radio_parms;
  168. struct wl128x_ini_general_params *gp = &nvs->general_params;
  169. int ret;
  170. if (!wl->nvs)
  171. return -ENODEV;
  172. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  173. if (!radio_parms)
  174. return -ENOMEM;
  175. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  176. /* 2.4GHz parameters */
  177. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  178. sizeof(struct wl128x_ini_band_params_2));
  179. memcpy(&radio_parms->dyn_params_2,
  180. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  181. sizeof(struct wl128x_ini_fem_params_2));
  182. /* 5GHz parameters */
  183. memcpy(&radio_parms->static_params_5,
  184. &nvs->stat_radio_params_5,
  185. sizeof(struct wl128x_ini_band_params_5));
  186. memcpy(&radio_parms->dyn_params_5,
  187. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  188. sizeof(struct wl128x_ini_fem_params_5));
  189. radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
  190. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  191. radio_parms, sizeof(*radio_parms));
  192. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  193. if (ret < 0)
  194. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  195. kfree(radio_parms);
  196. return ret;
  197. }