mp_dev.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright (c) 2013-2014, 2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #include "hif_io32.h"
  27. #include "hif_debug.h"
  28. /*chaninfo*/
  29. #define CHANINFOMEM_S2_READ_MASK 0x00000008
  30. #define CHANINFO_CTRL_CAPTURE_CHAN_INFO_MASK 0x00000001
  31. #define CHANINFO_CTRL_CHANINFOMEM_BW_MASK 0x00000030
  32. #define MULTICHAIN_ENABLE_RX_CHAIN_MASK_MASK 0x00000007
  33. /*agc*/
  34. #define GAINS_MIN_OFFSETS_CF_AGC_HIST_ENABLE_MASK 0x00040000
  35. #define GAINS_MIN_OFFSETS_CF_AGC_HIST_GC_MASK 0x00080000
  36. #define GAINS_MIN_OFFSETS_CF_AGC_HIST_VOTING_MASK 0x00100000
  37. #define GAINS_MIN_OFFSETS_CF_AGC_HIST_PHY_ERR_MASK 0x00200000
  38. #define AGC_HISTORY_DUMP_MASK (\
  39. GAINS_MIN_OFFSETS_CF_AGC_HIST_ENABLE_MASK| \
  40. GAINS_MIN_OFFSETS_CF_AGC_HIST_GC_MASK| \
  41. GAINS_MIN_OFFSETS_CF_AGC_HIST_VOTING_MASK| \
  42. GAINS_MIN_OFFSETS_CF_AGC_HIST_PHY_ERR_MASK \
  43. )
  44. #define BB_chaninfo_ctrl 0x1a370
  45. #define BB_multichain_enable 0x1a2a0
  46. #define BB_chn_tables_intf_addr 0x19894
  47. #define BB_chn1_tables_intf_addr 0x1a894
  48. #define BB_chn_tables_intf_data 0x19898
  49. #define BB_chn1_tables_intf_data 0x1a898
  50. #define BB_gains_min_offsets 0x19e08
  51. #define BB_chaninfo_tab_b0 0x03200
  52. #define BB_chaninfo_tab_b1 0x03300
  53. #define BB_watchdog_status 0x1a7c0
  54. #define BB_watchdog_ctrl_1 0x1a7c4
  55. #define BB_watchdog_ctrl_2 0x1a7c8
  56. #define BB_watchdog_status_B 0x1a7e0
  57. #define PHY_BB_CHN_TABLES_INTF_ADDR 0x19894
  58. #define PHY_BB_CHN_TABLES_INTF_DATA 0x19898
  59. #define PHY_BB_CHN1_TABLES_INTF_ADDR 0x1a894
  60. #define PHY_BB_CHN1_TABLES_INTF_DATA 0x1a898
  61. struct priv_ctrl_ctx {
  62. uint32_t chaninfo_ctrl_orig;
  63. uint32_t gain_min_offsets_orig;
  64. uint32_t anyreg_start;
  65. uint32_t anyreg_len;
  66. };
  67. static struct priv_ctrl_ctx g_priv_dump_ctx;
  68. static inline void set_target_reg_bits(void __iomem *mem, uint32_t reg,
  69. uint32_t bitmask, uint32_t val)
  70. {
  71. uint32_t value = hif_read32_mb(mem + (reg));
  72. uint32_t shift = 0;
  73. value &= ~(bitmask);
  74. while (!((bitmask >> shift) & 0x01))
  75. shift++;
  76. value |= (((val) << shift) & (bitmask));
  77. hif_write32_mb(mem + (reg), value);
  78. }
  79. static inline uint32_t get_target_reg_bits(void __iomem *mem,
  80. uint32_t reg, uint32_t bitmask)
  81. {
  82. uint32_t value = hif_read32_mb(mem + (reg));
  83. uint32_t shift = 0;
  84. while (!((bitmask >> shift) & 0x01))
  85. shift++;
  86. return (value >> shift) & bitmask;
  87. }
  88. void priv_start_cap_chaninfo(struct hif_softc *scn)
  89. {
  90. set_target_reg_bits(scn->mem, BB_chaninfo_ctrl,
  91. CHANINFO_CTRL_CAPTURE_CHAN_INFO_MASK, 1);
  92. }
  93. void priv_start_agc(struct hif_softc *scn)
  94. {
  95. g_priv_dump_ctx.gain_min_offsets_orig =
  96. hif_read32_mb(scn->mem + BB_gains_min_offsets);
  97. set_target_reg_bits(scn->mem, BB_gains_min_offsets,
  98. AGC_HISTORY_DUMP_MASK,
  99. 0x0f);
  100. }
  101. void priv_stop_agc(struct hif_softc *scn)
  102. {
  103. set_target_reg_bits(scn->mem, BB_gains_min_offsets,
  104. AGC_HISTORY_DUMP_MASK,
  105. 0);
  106. }
  107. void priv_dump_chaninfo(struct hif_softc *scn)
  108. {
  109. uint32_t bw, val;
  110. uint32_t len, i, tmp;
  111. uint32_t chain_mask;
  112. uint32_t chain0, chain1;
  113. chain_mask =
  114. get_target_reg_bits(scn->mem, BB_multichain_enable,
  115. MULTICHAIN_ENABLE_RX_CHAIN_MASK_MASK);
  116. chain0 = chain_mask & 1;
  117. chain1 = chain_mask & 2;
  118. HIF_TRACE("%s: E", __func__);
  119. bw = get_target_reg_bits(scn->mem, BB_chaninfo_ctrl,
  120. CHANINFO_CTRL_CHANINFOMEM_BW_MASK);
  121. if (bw == 0)
  122. len = 53;
  123. else if (bw == 1)
  124. len = 57;
  125. else if (bw == 2)
  126. len = 59 * 2 - 1;
  127. else
  128. len = 60 * 2 + 61 * 2;
  129. /*
  130. * each tone is 16 bit valid, write to 32bit buffer each.
  131. * bw==0(legacy20): 53 tones.
  132. * bw==1(ht/vht20): 57 tones.
  133. * bw==2(ht/vht40): 59+58 tones.
  134. * bw==3(vht80): 60*2+61*2 tones.
  135. */
  136. if (chain0) {
  137. hif_write32_mb(scn->mem + BB_chn_tables_intf_addr,
  138. 0x80003200);
  139. }
  140. if (chain1) {
  141. hif_write32_mb(scn->mem + BB_chn1_tables_intf_addr,
  142. 0x80003200);
  143. }
  144. set_target_reg_bits(scn->mem, BB_chaninfo_ctrl,
  145. CHANINFOMEM_S2_READ_MASK, 0);
  146. if (chain0) {
  147. if (bw < 2) {
  148. len = (bw == 0) ? 53 : 57;
  149. for (i = 0; i < len; i++) {
  150. val =
  151. hif_read32_mb(scn->mem +
  152. BB_chn_tables_intf_data) &
  153. 0x0000ffff;
  154. qdf_print("0x%x\t", val);
  155. if (i % 4 == 0)
  156. qdf_print("\n");
  157. }
  158. } else {
  159. len = (bw == 2) ? 59 : 60;
  160. for (i = 0; i < len; i++) {
  161. tmp =
  162. hif_read32_mb(scn->mem +
  163. BB_chn_tables_intf_data);
  164. qdf_print("0x%x\t", ((tmp >> 16) & 0x0000ffff));
  165. qdf_print("0x%x\t", (tmp & 0x0000ffff));
  166. if (i % 2 == 0)
  167. qdf_print("\n");
  168. }
  169. if (bw > 2) {
  170. /* bw == 3 for vht80 */
  171. hif_write32_mb(scn->mem +
  172. BB_chn_tables_intf_addr,
  173. 0x80003300);
  174. len = 61;
  175. for (i = 0; i < len; i++) {
  176. tmp =
  177. hif_read32_mb(scn->mem +
  178. BB_chn_tables_intf_data);
  179. qdf_print("0x%x\t",
  180. ((tmp >> 16) & 0x0000ffff));
  181. qdf_print("0x%x\t", (tmp & 0x0000ffff));
  182. if (i % 2 == 0)
  183. qdf_print("\n");
  184. }
  185. }
  186. }
  187. }
  188. if (chain1) {
  189. if (bw < 2) {
  190. len = (bw == 0) ? 53 : 57;
  191. for (i = 0; i < len; i++) {
  192. val =
  193. hif_read32_mb(scn->mem +
  194. BB_chn1_tables_intf_data) &
  195. 0x0000ffff;
  196. qdf_print("0x%x\t", val);
  197. if (i % 4 == 0)
  198. qdf_print("\n");
  199. }
  200. } else {
  201. len = (bw == 2) ? 59 : 60;
  202. for (i = 0; i < len; i++) {
  203. tmp =
  204. hif_read32_mb(scn->mem +
  205. BB_chn1_tables_intf_data);
  206. qdf_print("0x%x\n", (tmp >> 16) & 0x0000ffff);
  207. qdf_print("0x%x\n", tmp & 0x0000ffff);
  208. if (i % 2 == 0)
  209. qdf_print("\n");
  210. }
  211. if (bw > 2) {
  212. /* bw == 3 for vht80 */
  213. hif_write32_mb(scn->mem +
  214. BB_chn1_tables_intf_addr,
  215. 0x80003300);
  216. len = 61;
  217. for (i = 0; i < len; i++) {
  218. tmp =
  219. hif_read32_mb(scn->mem +
  220. BB_chn1_tables_intf_data);
  221. qdf_print("0x%x\t",
  222. ((tmp >> 16) & 0x0000ffff));
  223. qdf_print("0x%x\t", (tmp & 0x0000ffff));
  224. if (i % 2 == 0)
  225. qdf_print("\n");
  226. }
  227. }
  228. }
  229. }
  230. HIF_TRACE("%s: X", __func__);
  231. }
  232. void priv_dump_agc(struct hif_softc *scn)
  233. {
  234. int i, len = 30; /* check this value for Rome and Peregrine */
  235. uint32_t chain0, chain1, chain_mask, val;
  236. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  237. return;
  238. chain_mask =
  239. get_target_reg_bits(scn->mem, BB_multichain_enable,
  240. MULTICHAIN_ENABLE_RX_CHAIN_MASK_MASK);
  241. chain0 = chain_mask & 1;
  242. chain1 = chain_mask & 2;
  243. len = len << 1; /* each agc item is 64bit, total*2 */
  244. priv_stop_agc(scn);
  245. set_target_reg_bits(scn->mem, BB_chaninfo_ctrl,
  246. CHANINFOMEM_S2_READ_MASK, 0);
  247. HIF_TRACE("%s: AGC history buffer dump: E", __func__);
  248. if (chain0) {
  249. for (i = 0; i < len; i++) {
  250. hif_write32_mb(scn->mem +
  251. PHY_BB_CHN_TABLES_INTF_ADDR,
  252. BB_chaninfo_tab_b0 + i * 4);
  253. val = hif_read32_mb(scn->mem +
  254. PHY_BB_CHN_TABLES_INTF_DATA);
  255. qdf_print("0x%x\t", val);
  256. if (i % 4 == 0)
  257. qdf_print("\n");
  258. }
  259. }
  260. if (chain1) {
  261. for (i = 0; i < len; i++) {
  262. hif_write32_mb(scn->mem +
  263. PHY_BB_CHN1_TABLES_INTF_ADDR,
  264. BB_chaninfo_tab_b0 + i * 4);
  265. val = hif_read32_mb(scn->mem +
  266. PHY_BB_CHN1_TABLES_INTF_DATA);
  267. qdf_print("0x%x\t", val);
  268. if (i % 4 == 0)
  269. qdf_print("\n");
  270. }
  271. }
  272. HIF_TRACE("%s: AGC history buffer dump X", __func__);
  273. /* restore original value */
  274. hif_write32_mb(scn->mem + BB_gains_min_offsets,
  275. g_priv_dump_ctx.gain_min_offsets_orig);
  276. Q_TARGET_ACCESS_END(scn);
  277. return;
  278. }
  279. void priv_dump_bbwatchdog(struct hif_softc *scn)
  280. {
  281. uint32_t val;
  282. HIF_TRACE("%s: BB watchdog dump E", __func__);
  283. val = hif_read32_mb(scn->mem + BB_watchdog_status);
  284. qdf_print("0x%x\t", val);
  285. val = hif_read32_mb(scn->mem + BB_watchdog_ctrl_1);
  286. qdf_print("0x%x\t", val);
  287. val = hif_read32_mb(scn->mem + BB_watchdog_ctrl_2);
  288. qdf_print("0x%x\t", val);
  289. val = hif_read32_mb(scn->mem + BB_watchdog_status_B);
  290. qdf_print("0x%x", val);
  291. HIF_TRACE("%s: BB watchdog dump X", __func__);
  292. }